Auto Populate Values


F

Frank Py

I have 4 possible values that I would like to populate a text box with
depending on which 4 values are sleected in a select box. Is there an
example out there for this?

Thanks
Frank
 
Ad

Advertisements

S

Stuart Palmer

<script language="javascript">
function changetext(Dropdown_Val, Dropdown_Val_SI)
{
switch (Dropdown_Val[Dropdown_Val_SI].value)
{
case 'Cheese' :
document.MyForm.TextField.value="Cheese";
break
case 'Ham' :
document.MyForm.TextField.value="Ham";
break
default :
document.MyForm.TextField.value="No Value";
break
}
}
</script>

<form name="MyForm">
<select name="DropField" onChange="changetext(this,this.selectedIndex);">
<option value="Choose">Choose</option>
<option value="Ham">Ham</option>
<option value="Cheese">Cheese</option>
</select>
<input type="text" name="TextField">
</form>

Stu
 
J

JHLeong

Stuart Palmer said:
<script language="javascript">
function changetext(Dropdown_Val, Dropdown_Val_SI)
{
switch (Dropdown_Val[Dropdown_Val_SI].value)
{
case 'Cheese' :
document.MyForm.TextField.value="Cheese";
break
case 'Ham' :
document.MyForm.TextField.value="Ham";
break
default :
document.MyForm.TextField.value="No Value";
break
}
}
</script>

<form name="MyForm">
<select name="DropField" onChange="changetext(this,this.selectedIndex);">
<option value="Choose">Choose</option>
<option value="Ham">Ham</option>
<option value="Cheese">Cheese</option>
</select>
<input type="text" name="TextField">
</form>

Stu

Frank Py said:
I have 4 possible values that I would like to populate a text box with
depending on which 4 values are sleected in a select box. Is there an
example out there for this?

Thanks
Frank

<form name="MyForm">
<select name="DropField" onChange="document.MyForm.TextField.value =
this.options[this.selectedIndex].value;">
<option value="">Choose</option>
<option value="Ham">Ham</option>
<option value="Cheese">Cheese</option>
</select>
<input type="text" name="TextField">
</form>
 
E

Evertjan.

JHLeong wrote on 30 jun 2003 in comp.lang.javascript:
<form name="MyForm">
<select name="DropField" onChange="document.MyForm.TextField.value =
this.options[this.selectedIndex].value;">
<option value="">Choose</option>
<option value="Ham">Ham</option>
<option value="Cheese">Cheese</option>
</select>
<input type="text" name="TextField">
</form>

Nice and short, I changed it to:

<select
onChange="location.href =
this.options[this.selectedIndex].value;">
<option value="">Go to</option>
<option value="http://cnn.com/">CNN</option>
<option value="http://google.com/">Google</option>
</select>
 
Ad

Advertisements

E

Evertjan.

Frank Py wrote on 30 jun 2003 in comp.lang.javascript:
Thanks for the great examples. I just have one more question on this.
I'm using some sample code that uses ASP and the Response.Write to write
out all the html as it is called with functions. So when it hits the
first double quote in these examples, it thinks it the end of a state
ment:

Response.Write "<tr><td>Date</td>"

Use single quotes in javascript.

====================================

or change

Response.Write "<option value='http://google.com/'>Google</option>"

to

%><option value="http://google.com/">Google</option><%

because why use Response.Write in stead of straight html here ????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top