Click to See Complete Forum and Search --> : Dynamically Populating HTML Forms
Force
06-16-2003, 08:10 AM
I have a long form that I would like to shorten for users. For example, if they check the box "Military Service" using an on_click event, the HTML code would then populate the form at the point of the function, rather than having that code appear if it's not needed. I've seen it done, but haven't attempted it before.
Can someone point me in the right direction? I greatly appreciate it.
Mark F
maybe this helps:http://developer.apple.com/internet/javascript/dynamicforms.html
AdamGundry
06-16-2003, 08:39 AM
I believe this is normally done by making an element containing the form controls you want to hide invisible, using the CSS "display: none", then making it visible when required. Make sure you set change the value of the CSS with Javascript, so users with JS disabled can still use the form.
Adam
Gollum
06-16-2003, 08:41 AM
quite a broad question, but here are a few tips...
you will want to add an onclick handler to your checkbox...
<form name=myForm>
<input type=checkbox name=service value="military" onclick="FillFormMilitary();">Military Service
</form>
then you can write code to do whatever you like to the form...
<script language="Javascript">
function FillFormMilitary()
{
// change a text box...
document.myform.preferredWeapon.value = "M16";
// change a checkbox...
document.myForm.tourOfDuty.checked = true;
// change a combo...
document.myForm.rank.selectedIndex = 3;
}
</script>