Jump to content

help with select and text input


mpsn

Recommended Posts

Hi, I want the drop down select input to change the textbox to the appropriate phone number, but it's not working:

 

Here's the HTML:

<html>

<head>

<script type="text/javascript" src="js_.js"></script>

<body>

<form id="form_3">

<select id="select_2" onclick="getPhoneNumber( this.options[this.options.selectedIndex].value );">

<option value="pizza73">Pizza 73</option>

<option value="work">Work</option>

<option value="school">School</option>

</select>

 

<input type="text" id="phoneNumberText" value="displays phone number" />

 

</form>

</body>

</html>

 

Here's the external JS (js_.js):

var phoneBook = new Array();
phoneBook["pizza73"] = "780 473 7373";
phoneBook["work"] = "780 444 8621";
phoneBook["school"] = "780 444 8000";

function getPhoneNumber(selected)
{
var showPhoneNumber = document.getElementById("phoneNumberText").value;
showPhoneNumber = phoneBook[selected];
}

 

Any help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/254452-help-with-select-and-text-input/
Share on other sites

So basically, you're wanting the user to be able to select a name from a list, the value of which contains a phone number? Once they select a number, you want to then output that number to the user?

 

Have you considered using jQuery for this? It'd be extremely simple to accomplish.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.