Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Dropdown content alignment
04-10-2012, 10:20 AM #1
- Join Date
- Apr 2012
- Thanked 0 Times in 0 Posts
Dropdown content alignment
i have a requirement where in ... in a drop down i need to show 2 values for a single row...one to left most and one to right most... how to do that ?...
For example, i want to show student name and reg no both in the drop down and i want student name to the left most of the drop down and reg no to the right most of the drop down...
04-10-2012, 06:28 PM #2
- Join Date
- Jan 2011
- Thanked 940 Times in 937 Posts
We're going to make a string to use in the <option> tags that fits your requirements. The first thing we want to do is figure out the length we will allow for the name. I arbitrarily chose 7 char for the first name and the same for the second name separated by a space. This give us 15 chars for the name [You will have to figure out how your going to enforce this or what ever length you decide on]. A length must be picked in order to make the options look nice.
I next arbitrarily picked 12 as the length of the registration number. And chose 5 spaces or in this case dots to be the minimum distance between the two. Here is code with explanation for you.
<?php // First we make a string of dots // the total length of our finished string. // 15 (name len) + 5 (min dist.) +12 ( student number.) $line = str_pad('',32,"."); // Next three strings from a database query $number = '123456789012'; $first = 'vaibhav'; $last = 'kushadi'; // put the name together in $left $name = array($first, $last); $left = implode(' ', $name); // replace some of the dots in $line // to give us the student name to the left // and the ID number to the right // with some thing seoerating them $line = substr_replace($line, $left, 0, strlen($left)); $line = substr_replace($line, $number, 20); // this is optional, replaces dots //with spaces which are bigger $linea = str_ireplace('.',' ',$line) ?> <!--Make the dropdown box--> Student Names and ID Numbers<br /> <select> <option></option> <option><?php echo $line; ?></option><!-- this has dots--> <option><?php echo $linea; ?></option><!-- this has spaces--> </select>