
-----------------------------------
waltg72
Sun Aug 29, 2010 7:14 pm

Auto Populate HTML Form textbox after selecting an item from my html listmenu
-----------------------------------
Hello Guys,

I am developing a project particularly in enrollment system using php and mysql.

I would like to know if it is possible to produce a auto populated textbox of my html form after selecting
an item from my listbox with php?

Example:

MYSQL Table

Fields

Lastname
Firstname

Sample Data 1
Armstrong
Toby

Sample Data 2
Jimenez
Joy



HTML FORM


  Lastname
  
  
  
   
  Firstname
  
  
  


What I want to do is, I want to auto populate the firstname textbox based from the selected lastname,
without using the submit button. Meaning, once I click the listbox and choose a lastname. The firstname
with that lastname will display automatically to my firstname textbox based from mysql database.

thanks in advance.

-----------------------------------
Bored
Thu Sep 09, 2010 6:27 pm

Re: Auto Populate HTML Form textbox after selecting an item from my html listmenu
-----------------------------------
You're going to need to use some javascript here. Look into HTML DOM Event Objects, specifically the onchange event.

-----------------------------------
waltg72
Thu Sep 09, 2010 7:46 pm

Re: Auto Populate HTML Form textbox after selecting an item from my html listmenu
-----------------------------------
I believe onchange() will execute the function in javascript once I choose an item from my dropdown list, or let say listmenu.

My next question is, How will I pass the value to my textbox?

Here is my html form source:





  
  
    Option 1
    Option 2
    Option 3
    Option 4
  
  
  
  
  





---------------------------------------------------------------
Question:
1. How will I pass the value that I choose from my list/menu to my textfield?

-----------------------------------
Zren
Thu Sep 09, 2010 8:22 pm

Re: Auto Populate HTML Form textbox after selecting an item from my html listmenu
-----------------------------------
.value is the property of the text in the textfield or it is the value inside the option. Alternatively, .text is the property of the text viewable to select from for the option.
select is the array of options in the selection dropdown.
select.selectedIndex is the option currently selected.
