Need to auto fill text field based on drop down

Posted on 2008-11-13
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

    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

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This video teaches viewers about errors in exception handling.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now