Javascript help
Author
Discussion

BliarOut

Original Poster:

72,863 posts

269 months

Thursday 28th July 2005
quotequote all
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

supersport

4,637 posts

257 months

Thursday 28th July 2005
quotequote all
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

BliarOut

Original Poster:

72,863 posts

269 months

Thursday 28th July 2005
quotequote all
Threw some MySQL queries at the select it and it's doing just what I want it to now.

Thank you kindly