Using JQuery and a drop-down Select field to populate multiple text fields

Posted on 2009-04-01
Last Modified: 2012-05-06
I have a simple drop-down select field in a form which contains 4 other text fields. When a user selects an item from the select list, I want to change the default value in the 4 other fields based on the selected item.
I'd like to do so using JQuery.
The select field is generated on the server from mysql database. I can generate anything necessary in the Javascript.

I was thinking I could generate a Javascript Array containing the necessary data to populate the text fields.
Is this method feasible? Please provide an example.
Question by:bhlang
LVL 19

Accepted Solution

Albert Van Halen earned 250 total points
ID: 24048562
Look at the code.
Perhaps it's working for you
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">


		<title>DropDownList Populate</title>

		<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

        <script src="" type="text/javascript"></script>



<script type="text/javascript">

// array list generated on the server

var tbValues = [];

tbValues["1"] = ['The first textbox', '', 'The 3rd', 'Last but not least; the 4th'];

tbValues["2"] = ['The first textbox', 'The second one', 'The 3rd', 'Last but not least; the 4th'];

tbValues["option3"] = ['3 : The first textbox', '3 : The second', '3 : The 3rd', '3 : Last but not least; the 4th'];

tbValues["4"] = ['4 - empty', '4 - The second', '4 - The 3rd', '4 - Last but not least; the 4th'];

function changeDropDownList() {

	var val = $(this).val();

	if (val != "") {





	} else {

		// Clear the textboxes







$(function() {

	// Bind the change event

	$("#myDropDownList").bind("change", changeDropDownList);




		<select id="myDropDownList">

			<option value="">Please select</option>

			<option value="1">One</option>

			<option value="2">Two</option>

			<option value="option3">Three</option>

			<option value="4">Four</option>


		<input type="text" id="myTextBox1" />

		<input type="text" id="myTextBox2" />

		<input type="text" id="myTextBox3" />

		<input type="text" id="myTextBox4" />




Open in new window


Author Closing Comment

ID: 31565578
First class solution! Thank you very much.

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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