WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to populate an input field of type text from a select box with JavaScript.
Categories : Java Script
Boaz Yahav
Date : Aug 23rd 2001
Grade : 4 of 5 (graded 4 times)
Viewed : 11574
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Boaz Yahav
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Sometimes you need to allow users to choose a value from a select box (pull down menu) and
have the value they chose show up in another input field of type text (for example).

Here is how to do it :

Add this Jscript function to your page.


<SCRIPT LANGUAGE="JavaScript">
function UpdateField(index) {
form=document.FormName;
form.TextFieldName.value = form.SelectFieldName.options[index].text
}
</SCRIPT>


o FormName is the name of your <FORM>

o TextFieldName is the name of the field you want the Selected text to be in.

o SelectFieldName is the name of the Select field you are choosing from.



The call to the function should be like this :


<SELECT onChange="UpdateField(this.selectedIndex)"; NAME="SelectFieldName">

In case you want the value of the field and not the text that is shown in the pull down menu,
all you need to change is the next line in the function :

form.TextFieldName.value = form.SelectFieldName.options[index].text

to

form.TextFieldName.value = form.SelectFieldName.options[index].value



How to get the Focus (Cursor) into a Form-Element.
Categories : HTML, Java Script
Bouncing Marquee at Status Bar
Categories : Java Script, HTML, Browsers
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
PHP Array to Javascript Object
Categories : PHP, Arrays, Java Script
JavaScript IP validation; IP validation script;
Categories : Java Script, Algorithms
JavaScript Fade In Text Messages
Categories : Java Script, DHTML
JavaScript dropdown list menu to switch any page.
Categories : Java Script, Beginner Guides, Form Processing
Flash Your Message at Status Bar
Categories : Java Script, Browsers
Local Time clock and Server time usign PHP and JavaScript
Categories : PHP, Java Script, Date Time, Beginner Guides
Page Loading Message shown during the time your site's page is being loaded.
Categories : HTML, CSS, Java Script
A simple configuration file editor to ease you life in setting up php applications. Reads variables from a given file automatically and displays current value. New value will be written to file after submit.
Categories : PHP, Filesystem, Regexps, Java Script
Email Address Protection (Avoide SPAM)
Categories : Java Script, Email, Encryption
Remote Scripting: send form POST data to a script and insert the results into a page without refreshing the page.
Categories : PHP, AJAX, HTML and PHP, Java Script
Install Flash player plug-in
Categories : Flash, Java Script
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL