Need to auto fill text field based on drop down

Posted on 2008-11-13
Medium Priority
Last Modified: 2012-05-05
I need javascript to do the follow bellow is the code I use

I need it so if someone selects  11 from the second drop down the amount feild would put a value 1 in place
for example
11 = 1
12 = 3
13 = 6
21 = 10
22 = 13
23 =30

I been looking everywhere and found nothing

I am very new at coding and need this
Please help
function setOptions(chosen) {
var selbox = document.myform.service;
selbox.options.length = 0;
if (chosen == " ") {
  selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
if (chosen == "1") {
  selbox.options[selbox.options.length] = new Option('11','11');
  selbox.options[selbox.options.length] = new Option('12','12');
  selbox.options[selbox.options.length] = new Option('13','13');
if (chosen == "2") {
  selbox.options[selbox.options.length] = new Option('21','21');
  selbox.options[selbox.options.length] = new Option('22','22');
  selbox.options[selbox.options.length] = new Option('23','23');
<form name="myform" method="post" action="submit.php" onSubmit="document.myform.service.options[document.myform.service.selectedIndex].value;">
	<select name="product" size="1" onchange="setOptions(document.myform.product.options[document.myform.product.selectedIndex].value);">
	<option value=" " selected="selected"> </option>
	<option value="1">1</option>
	<option value="2">2</option>
	<select name="service" size="1">
	<option value=" " selected="selected">Please select one of the options above first</option>
	<td><input  id="amount" name="amount"></td></tr>
  <tr><td><input type="submit" value="Send" name="submit"></td></tr>

Open in new window

Question by:adamn123
1 Comment
LVL 15

Accepted Solution

MMDeveloper earned 600 total points
ID: 22951233
try this
<select name="service" size="1" onchange="updateAmt(this)">
        <option value=" " selected="selected">Please select one of the options above first</option>
<script type="text/javascript">
function updateAmt(el) {
	var amt = "";
	switch(el.value) {
		case "11":
			amt = 1;
		case "12":
			amt = 3;
		case "13":
			amt = 6;
	if (amt != "") {
		document.getElementById("amount").value = amt;
	} else {}

Open in new window


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question