View Full Version : removing a selected item in an html form

12-29-2009, 09:25 PM
I have two dropdowns. A selection from the first triggers the options for the second. For both forms the clicked option is selected and moved to the top of the list. Now the problem is what if, having clicked an option in the second dropdown, the user changes their mind and goes back to the first dropdown and clicks a different item ? My script rechanges the options in list two but what I can't do is get the original list two 'selected' to disappear. I've tried everything using php but it either doesn't work or doesn't look right.
I think the answer rests with javascript. I searched around and believe I need to use another onChange statement (I've already got one for something else from DJ). I found this:
<script type="text/JavaScript">
var formObj = document.forms['product'];
onChange= formObj.mySelect.options.length = 0;
Now I think it needs to be connected with this php statement:
echo"<option value = '$experience' selected>$experience<option />";
because I want this selected variable to stop being selected when the user hits a second choice from the first dropdown.
My problem is that I have no idea how to put the two ideas together.
Could someone help ?
PS I think this: onChange= formObj.mySelect.options.length = 0;
means...when you hit the list item, make the form 'selected' equal nothing.
Now if I'm wrong, you might just put me right.

01-09-2010, 11:18 PM
Hi - if you read my problem above you will no doubt be aware that my javascript idea for a solution is a non-starter. It appears that javascript doesn't influence php directly. Anyway, I went back to php and realised that one of DJ's videos did indeed have the solution - just couldn't see it at first. This does what I was looking for.

<div id="Layer61">
<select name="name_one" size="14" MULTIPLE onChange="document.forms[0].submit();">
<option value ="" selected>INNER THOUGHTS LIST<option />
@$special_word = $_POST["special_word"];
@$another_word = $_POST["special_idea"];
echo"<option value 1 = '$another_word' selected>$another_word<option />";
echo"<option value 1 ='' ><option />";
The trick is to label the option value ie 1.