drop down list problems

Discussion in 'JavaScript' started by zhinigami, Jun 6, 2007.

  1. #1
    Hi all,

    I have problem with this combo box or drop down list using javascript in php. I found that it cant select the first option's value (there are value=0, value=1, value=2 but it doesn't work with the 1st option.) Can someone tell me where to correct it's value so that it can select the 1st option too.
    Thank you.

    
    function jumpMenu(target,selObj,restore){ 
      if (selObj.selectedIndex>0 && selObj.options[selObj.selectedIndex].value != ''){
        window.open(selObj.options[selObj.selectedIndex].value,target);}
      else if(selObj.options[selObj.selectedIndex].value == '')  {selObj.selectedIndex=0;}
      if (restore) selObj.selectedIndex=0;
    }
    
    .....
    <tr class="content"><!--<form method="post" name="form2" action="what_on1.php"> -->
                    <td width="18%"><select name="select3" id="s3" onChange="javascript:jumpMenu('_top',this,0);">
                      <option value="what_on1.php?pid=0" <? if($_GET['pid']==0) {?>selected<? } ?>>10 per page</option>
                      <option value="what_on1.php?pid=1" <? if($_GET['pid']==1) {?>selected<? } ?>>20 per page</option>
                      <option value="what_on1.php?pid=2" <? if($_GET['pid']==2) {?>selected<? } ?>>30 per page</option>
                    </select></td>
    
    Code (markup):
     
    zhinigami, Jun 6, 2007 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you need a "starting" option.

    <select name="select3" id="s3" [B]onchange="jumpMenu('_top',this,0)"[/B]>
       [B]  <option value=""> Make a Selection </option>[/B]
         <option value="what_on1.php?pid=0" <? if($_GET['pid']==0) {?>selected<? } ?>>10 per page</option>
         <option value="what_on1.php?pid=1" <? if($_GET['pid']==1) {?>selected<? } ?>>20 per page</option>
         <option value="what_on1.php?pid=2" <? if($_GET['pid']==2) {?>selected<? } ?>>30 per page</option>
    </select>
    Code (markup):
     
    Mike H., Jun 6, 2007 IP
  3. zhinigami

    zhinigami Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is there any way to make it without starting option? Let's say the pid=0 is the "starting" option where it can be selected and functioned as well? It's ok, I just wanna know only...If there is no other way, I'll follow your advice.

    Thank You very much..
     
    zhinigami, Jun 6, 2007 IP
  4. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Drop down boxes automatically display the first option unless another option is selected <option vale='....' selected>.
    Have you tried leaving out the php code in the first option - you don't need it.
    so it should look like:
    <option value="what_on1.php?pid=0">10 per page</option>

    I think this should do it.
     
    NoamBarz, Jun 7, 2007 IP