Javascript help
Discussion
I need a little help. I have a form, but I need to change it a bit. At the moment I have a drop down box populated by a MySQL query. It picks the role of a person from a list of roles in a roles table. Then the "selected" value is the role in the main table. Great, except if someone deletes the role from the roles table (which they can do by design). Then it all goes pear shaped.
What I want to do instead is to display the role in a text box and have a drop down next to it. Effectively the text box is free type text, but if they use the dropdown list, it populates the text box.
So I want to trigger some JS "on update" of the dropdown and put that value in the text box.
Does anyone have a snippet of code that will do what I want?
Thanks,
Rob
[small]Am I making any sense at all here?[/small] :D
What I want to do instead is to display the role in a text box and have a drop down next to it. Effectively the text box is free type text, but if they use the dropdown list, it populates the text box.
So I want to trigger some JS "on update" of the dropdown and put that value in the text box.
Does anyone have a snippet of code that will do what I want?
Thanks,
Rob
[small]Am I making any sense at all here?[/small] :D
Here you go, this example should do the trick.
S
<HTML>
<HEAD>
<TITLE>Testing SCript</TITLE>
</HEAD>
<script language="JavaScript1.1">
function chngValue(f)
{
f.spinval.value = f.mylist.options[f.mylist.selectedIndex].text;
}
</SCRIPT>
<BODY>
<FORM>
<txt>
<p><input type="text" name=spinval size="20"><select size="1" name=mylist onChange="chngValue(
this.form);">
<option selected>First</option>
<option>Second</option>
<option>Third</option>
</select></p>
</txt>
</FORM>
</BODY>
</HTML>
>> Edited by supersport on Thursday 28th July 11:50
S
<HTML>
<HEAD>
<TITLE>Testing SCript</TITLE>
</HEAD>
<script language="JavaScript1.1">
function chngValue(f)
{
f.spinval.value = f.mylist.options[f.mylist.selectedIndex].text;
}
</SCRIPT>
<BODY>
<FORM>
<txt>
<p><input type="text" name=spinval size="20"><select size="1" name=mylist onChange="chngValue(
this.form);">
<option selected>First</option>
<option>Second</option>
<option>Third</option>
</select></p>
</txt>
</FORM>
</BODY>
</HTML>
>> Edited by supersport on Thursday 28th July 11:50
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



