spenceddd Posted December 29, 2009 Share Posted December 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/ Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985300 Share on other sites More sharing options...
spenceddd Posted December 29, 2009 Author Share Posted December 29, 2009 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... Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985303 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985305 Share on other sites More sharing options...
spenceddd Posted December 29, 2009 Author Share Posted December 29, 2009 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? Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985308 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 Yeah, it will always be there. you can remove it onclick etc but the best way to handle it is to have either a javascript form validation script or a handle it with PHP. Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985309 Share on other sites More sharing options...
spenceddd Posted December 29, 2009 Author Share Posted December 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/186566-how-to-exclude-the-caption-on-a-drop-down-list-when-it-is-pulled-down/#findComment-985463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.