Forum Moderators: coopster
Basically I am trying to find out how to populate form field values with data from other form field values. For instance I have come across many forms where I filled in my name and address etc as my contact details then say under administrator details it asks for similar information again with a button/tickbox that you can choose that says something along the lines of 'tick here if these details are the same as above' and once you do all the data you entered previously is inserted. I cant find any information on how to do this. Does anybody know or can anyone point me in the right direction.
<script type="text/javascript">
/*<![CDATA[*/ /*for valid xhtml*/
window.onload = function(){document.forms.addressForm.reset();}/*** Resets form if page refreshed ***/
function duplicate()
{
var ship = document.getElementById("shipAddressBox");
if (ship.value.length > 0) /*** check the shipping address has been filled in (length > 0)***/
{
document.getElementById("billAddressBox").value = ship.value; /*** fills the billing address box in with the shipping address box's value ***/
}
else
{
alert("Sorry, you must fill in your shipping address first!");
document.getElementById("yes").checked = false; /*** unchecks the radio input ***/
}
}
/*]]>*/
</script>
<form action="" name="addressForm">
<p>Please enter shipping address:<input type="text" id="shipAddressBox" /><br />
Billing address same as shipping address?<br />
(must check one)   Yes:<input type="radio" id="yes" name="confirm" onclick="duplicate();" />
  No:<input type="radio" id="no" name="confirm" onclick="this.form.billAddressBox.value='';" /><br />
Please enter billing address:<input type="text" id="billAddressBox" name="billAdd" /><br />
<input type="reset" /></p></form>
Of course this is a simplified form and script. You would probably want to also verify onsubmit that one of the radio inputs has been checked also, and do more checking of the inputs values. But this is just an example, hope it helps!