Click to See Complete Forum and Search --> : Question
jahotchk
11-05-2003, 03:17 PM
In VB you can select a value from a pull down menu and tell it to populate a text field, like so:
if dpLocation.value = USA then
txtCountryName.text = United States
End If
Is there a way to do the same in JavaScript? If so, can someone be kind enough to post the syntax.
Thank you!
Jason
jahotchk
11-05-2003, 03:57 PM
This is what I think I am supposed to do, and what I have tried (although unsuccessfully)
First Define A Function:
function fillPhoneNumber()
{
if (document.HelpDesk.Location.value == "Pleasanton")
document.HelpDesk.PersonsPhone.value ==
2091112222
return false;
}
Then in my Form, <input name="Location" onChange="fillPhoneNumber();">
This doesn't work, but I wanted to show that I have put some effort into trying to figure this out myself. I am just not familiar with the syntax.
Thanks!
AdamBrill
11-05-2003, 04:01 PM
Try this instead of what you have:
<script type="text/javascript">
function fillPhoneNumber()
{
if (document.HelpDesk.Location.value == "Pleasanton"){
document.HelpDesk.PersonsPhone.value = "2091112222";
}
}
</script>
<input type="text" name="Location" onChange="fillPhoneNumber();">
jahotchk
11-05-2003, 04:22 PM
Thanks for your Reply Adam. I utilized the code you provided, however, I am still receiving the same error.
Stating that an object is expected at line 59, which is my <input> line.
Any other suggestions? Is what I am trying to do even possible? Is a text box suitable for this or should I use another input selector.
Thanks!
Jason
AdamBrill
11-05-2003, 04:27 PM
Here is a complete working example:<script type="text/javascript">
function fillPhoneNumber()
{
if (document.HelpDesk.Location.value == "Pleasanton"){
document.HelpDesk.PersonsPhone.value = "2091112222";
}
}
</script>
<form name="HelpDesk">
Location: <input type="text" name="Location" onChange="fillPhoneNumber();"><br>
Phone: <input type="text" name="PersonsPhone">
</form>
jahotchk
11-05-2003, 04:55 PM
This is great... However, I need to use a "select" control so that a user can choose their location from a drop down list.
The example you provided works great is the user types in the name, however, I can't rely on them spelling correctly (ironcially enough). So I want to give them the choices.
Can you assist in providing syntax to work with a drop down list?
Thanks for your help Adam, it is greatly appreciated.
Jason
AdamBrill
11-05-2003, 05:03 PM
Originally posted by jahotchk
The example you provided works great is the user types in the name, however, I can't rely on them spelling correctly (ironcially enough).lol, how true. ;) Try this:<script type="text/javascript">
function fillPhoneNumber()
{
if (document.HelpDesk.Location.options[document.HelpDesk.Location.selectedIndex].innerHTML == "Pleasanton"){
document.HelpDesk.PersonsPhone.value = "2091112222";
}
}
</script>
<form name="HelpDesk">
Location:
<select name="Location" onChange="fillPhoneNumber();">
<option>Please choose your location:</option>
<option>Pleasanton</option>
<option>Other Place...</option>
</select>
Phone: <input type="text" name="PersonsPhone">
</form>
jahotchk
11-05-2003, 05:20 PM
Adam, you rock!
This is exactly what I was looking for. It works perfectly and I even added the rest of my locations.
Thanks for your help!
Jason
AdamBrill
11-05-2003, 05:25 PM
No problem. :)