troubleshooting Question

populate text box based in selection from drop down

Avatar of animated405
animated405 asked on
JavaScript
16 Comments1 Solution862 ViewsLast Modified:
Hello,
I have a form with a place to add/edit address information. I'm trying to add a quickname type selection at the top of that form. When the user selects a saved address from this list I would like to populate the form with the address properties without reloading the page.

What I tried to do was write out some javascript arrays inside of a function containing the values for the different saved address in the users account, corresponding to the id's from the database. Then activate that function with an on onchange event for the select box which would pass in the id that was selected. My hopes was that the function could set the value of the corresponding text box. It's not working. Code I was using below..

<script language="javascript">
function doPostBack(){
var a_422347=new Array(11)
a_422347[0]="422347"
a_422347[1]=""
a_422347[2]="Fmaous Person"
a_422347[3]=""
a_422347[4]="1 Hollywood Blvd"
a_422347[5]=""
a_422347[6]="Los Angeles"
a_422347[7]="CA"
a_422347[8]="12345"
a_422347[9]=""
a_422347[10]="testingnumber2@fakeaddress.com"
a_422347[11]="saved address 2"
var a_422348=new Array(11)
a_422348[0]="422348"
a_422348[1]=""
a_422348[2]="My Address"
a_422348[3]=""
a_422348[4]="Fake Street"
a_422348[5]=""
a_422348[6]="New York"
a_422348[7]="NY"
a_422348[8]="11111"
a_422348[9]=""
a_422348[10]="test@fakeaddress.com"
a_422348[11]="saved address 2"

this.form.ShipToName.Value='a_' + document.newform.address_quickname.value + '[0]';
}
</script>

Bascially the form:
<form name="newform" method="post" action="">
<input type="hidden" name="AddressMode" value="Submit">
<select name="address_quickname" onChange="doPostBack();">
<option value="">Address Book</option>
<option value="">-------------------------</option>
<option value="422347">saved address 2</option>
<option value="422348">saved address 1</option>
</select>
<br>
*Name<br>
<input type="text" name="ShipToName" value="">
Company<br>
<input type="text" name="ShipToCompany" Value="">
Address 1 *<br>
<input type="text" name="ShipToAddress1" value="">
Address 2<br>
<input type="text" name="ShipToAddress2" value="">
City *<br>
<input type="text" name="ShipToCity" Value="">
Zip Code *<br>
<input type="text" name="ShipToZip" value="">
Phone<br>
<input type="text" value="">
Email Address<br>
<input type="text" value="">
<input name="create" type="image" src="button.gif" border="0">
</form>

How do I do this? Thanks in advance!!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros