Results 1 to 3 of 3

Thread: [RESOLVED] Most efficiant way to handle input of "selected" in form

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    431

    Resolved [RESOLVED] Most efficiant way to handle input of "selected" in form

    lets say you have a form, each entry hold a month, example:

    Code:
    <option value='1'>January</option><option value='2'>February</option><option value='3'>March</option><option value='4' SELECTED>April</option><option value='5'>May</option><option value='6'>June</option><option value='7'>July</option><option value='8'>August</option><option value='9'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option>
    I then have a $CurrentMonth which holds the int value for the month that I want selected.

    Is there some trick to doing this effectly of do i simple do something like:

    echo start of data

    check if check should be there

    echo end of data

    then do that for each month... (ive done this before but it just seem VERY inefficiant and messy)

    edit: this is what I currently have.... problem is its very bad code... and I also got 2 do this with the year (and there are many more then 12 events).... Maybe it can be done with a array or something...
    Code:
    if (intval($vMonth) == 1) $DateInput.= " SELECTED";
    			$DateInput.= ">January</option><option value='2'";
    			
    			if (intval($vMonth) == 2) $DateInput.= " SELECTED";
    			$DateInput.=">February</option><option value='3'";
    			
    			if (intval($vMonth) == 3) $DateInput.= " SELECTED";
    			$DateInput.=">March</option><option value='4'";
    			
    			if (intval($vMonth) == 4) $DateInput.= " SELECTED";
    			$DateInput.=">April</option><option value='5'";
    			
    			if (intval($vMonth) == 5)  $DateInput.= " SELECTED";
    			$DateInput.=">May</option><option value='6'";
    			
    			if (intval($vMonth) == 6) $DateInput.= " SELECTED";
    			$DateInput.=">June</option><option value='7'";
    			
    			if (intval($vMonth) == 7) $DateInput.= " SELECTED";
    			$DateInput.=">July</option><option value='8'";
    			
    			if (intval($vMonth) == 8) $DateInput.= " SELECTED";
    			$DateInput.=">August</option><option value='9'";
    			
    			if (intval($vMonth) == 9) $DateInput.= " SELECTED";
    			$DateInput.=">September</option><option value='10'";
    			
    			if (intval($vMonth) == 10) $DateInput.= " SELECTED";
    			$DateInput.=">October</option><option value='11'";
    			
    			if (intval($vMonth) == 11) $DateInput.= " SELECTED";
    			$DateInput.=">November</option><option value='12'";
    			
    			if (intval($vMonth) == 12) $DateInput.= " SELECTED";
    			$DateInput.=">December</option>";
    Last edited by Zeratulsdomain; Apr 30th, 2008 at 02:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width