Jump to content

How to exclude the caption on a drop down list when it is pulled down


spenceddd

Recommended Posts

Hi,

 

I am a bit stuck working on a drop down list in my form which is annoying since I already have a drop down list that does work elsewhere in my form. Being very new to php and html I can't quite get my head round it.

 

You can see the problematic dropdown here: http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php

 

It is the Manage Skills list drop down. Before the list is clicked on it shows the text 'Choose Skill Item', when it is clicked on it stil shows that text as an option which is the problem.

 


<select name="skillsListDropDown" onchange="this.form.skillField.value=this[this.selectedIndex].text">
      <option value="Choose" >Choose Skill Item</option>
      <?php do { ?>
      <option value="<?php echo $row_skillsList['id']?>"<?php if (!(strcmp($row_skillsList['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_skillsList['name']?></option>
      <?php 
} while ($row_skillsList = mysql_fetch_assoc($skillsList)); 
  $rows = mysql_num_rows($skillsList); 
  if($rows > 0) { 
      mysql_data_seek($skillsList, 0); 
      $row_skillsList = mysql_fetch_assoc($skillsList); 	  
  } 
?>
    </select>

Can anyone see how to fix this...?

 

Thanks

 

Spencer

You could do an onchange event using javascript so when an item is selected that box becomes disabled..

onchange="if(this.value != 'Choose an Item') { document.getElementById('choose_item').disabled = true; }" or something

 

When document.getElementById('choose_item') is the first value of course..

Thanks Buddski I will try that although I already have an onchange event on that drop down. Do you know the code to add another.

 

The existing code looks like this, it populates a text box next to it:

 

onchange="this.form.skillField.value=this[this.selectedIndex].text"

 

I'm guessing you just add an && but i'd be guessing...

convert it to a function

onchange="myfunction(this);"

function myfunction(obj) {
obj.form.skillField.value=obj[obj.selectedIndex].text;
if(obj.value != 'Choose an Item') { 
document.getElementById('choose_item').disabled = true; 
}
}

 

Might need a bit of work but its a start for you..

OK thanks I'll give it a go.

 

Doesn't an onchange function only kick-in when you actually select an tem from the list....meaning that the 'choose item' would still be there when the list is initially expanded?

Ok well thanks for the advice Buddski, due to my lack of experience I don't fullly understand yet but it doesn't matter, it's not an vital part of the form. Hopefully I will be able to refer back to this when my understanding has improved a bit.

 

Appreciated.

 

Spencer

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.