Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.