Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onselect or Onchange with mysql query or function

Status
Not open for further replies.

proggybilly

Programmer
Apr 30, 2008
110
US
I have a form I am working on where a select box is created using php and mysql. I have text boxes on my form that need to be filled with what ever data goes along with what is selected in the select box.

For instance, the function creating the drop down box is run and it fills with WK YR MO. I then want to be able to run a function based off of what ever is selected at the time to get the other info that goes along with the selection (i.e. WK has description and a few fields which indicate notify days.)

I have never done Javascript and think this is the best route to go. Any and all help is GREATLY appreciated.
 
attach an onchange event to the select and point it at a function that you put in <script> tags within your <head> section

Code:
<select name="mySelect" onchange="processSelectChange(this);">
<option value="WK">WK</option>
</select>

in the function test the value of the select control.

Code:
function processSelectChange(elem){
var val = elem.options[elem.selectedIndex].value;
switch (val){
 case 'WK': 
   //do something;
   break;
 case 'YR':
    //do something else
    break
  // ..etc..
}

to set the value of another control, at its simplest just use this

Code:
document.getElementById('IDofControl').value = 'my value';

this is ok for text controls (text/textarea). for radios and checkboxes set the 'checked' value instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top