Lets say I have a database.. I also have an HTML form to add/edit the database.. If a user already has data in the database then the form should already be filled out with the data on load. This means the text field values, radio button values, and of course pulldown menu's.
EXAMPLE::
If the database value of the pulldown menu for "country" is "AK" then the pulldown will have "Arkansas" already selected for the user.
If the database value of the pulldown menu for "country" is "AL" then the pulldown will have "Alabama" already selected for the user.
If there is no value in the database for "country" then the pulldown menu will not have any pre-selected values.
So basically what i am trying to do is create a javascript that can accomplish this. I am using a template system to fill out the javascript values and got it to work with radio buttons and text fields. I just can get it to work with pulldowns.
This is the form I am using:
<body onload=FillOutOptions()
<form name=theForm>
<select name=country>
<option value="">
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AS">Am. Samoa
</select>
This is what currently works..
<script language="javascript">
<!--//
function FillOutOptions() {
document.theForm.gender[<%TEMPLATE VALUE FOR GENDER%>].checked = true; // This selects the radio button
document.theForm.name.value = "<%TEMPLATE VALUE FOR NAME%>"; // This fills in the name field
}
//-->
</script>
Just need it to work with pulldowns...
EXAMPLE::
If the database value of the pulldown menu for "country" is "AK" then the pulldown will have "Arkansas" already selected for the user.
If the database value of the pulldown menu for "country" is "AL" then the pulldown will have "Alabama" already selected for the user.
If there is no value in the database for "country" then the pulldown menu will not have any pre-selected values.
So basically what i am trying to do is create a javascript that can accomplish this. I am using a template system to fill out the javascript values and got it to work with radio buttons and text fields. I just can get it to work with pulldowns.
This is the form I am using:
<body onload=FillOutOptions()
<form name=theForm>
<select name=country>
<option value="">
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AS">Am. Samoa
</select>
This is what currently works..
<script language="javascript">
<!--//
function FillOutOptions() {
document.theForm.gender[<%TEMPLATE VALUE FOR GENDER%>].checked = true; // This selects the radio button
document.theForm.name.value = "<%TEMPLATE VALUE FOR NAME%>"; // This fills in the name field
}
//-->
</script>
Just need it to work with pulldowns...