Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Copy value of drop down meny to text field on change

I have an ASP/VBScript page. Using classic ASP, dreamweaver and ms sql 2008

In the ASP I have a drop down menu named 'PetNameSel'. When I make a selection at any given time I need for it to copy the value selected to a text field in the same form. the text field to where it should copy the value is named 'PetName'.

I guess I need a javascript and an 'onchange' action on the drop down ?   Help with both is appreciated.
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

function ex(val)
{
document.getElementById("'PetName").value=val;
}

<select id='PetNameSel' onchange='ex(this.value)'>
<option value='print'>print</option >
<option value='copy'>copy</option >

</select>

Open in new window

function ex(val)
{
document.getElementById("'PetName").value=val;
}

<select id='PetNameSel' onchange='ex(this.value)'>
<option value='print'>print</option >
<option value='copy'>copy</option >

</select>
<input type='text' id='PetName'>

Open in new window

Avatar of Aleks

ASKER

I added this to the drop down menu:

<select name="PetNameSel" class="bodytext" id="PetNameSel" onchange='ex(this.value)'>

And this is the code I added to the page:

<script language="javascript">
function ex(val)
{
document.getElementById("'PetName").value=val;
}
</script>


But nothing happened when I made my selection.  What am I missing ?
document.getElementById("'PetName").value=val;

in the above line quotes were wrong.replace with below one;

document.getElementById("PetName").value=val;
ASKER CERTIFIED SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Perfect, thanks !