Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button ... Automatically fill in shipping address 1

Status
Not open for further replies.

Sibylle

Technical User
Jul 2, 2001
13
US
Is there a way of having the shipping address automatically filled in (copying it from the billing address) when the visitor ticks a radio button?

The form I am working with is: ...

I have tried everything, but wasn't able to get that to work.

Your help would be appreciated.

Sibylle Faye
 
First I would change the radio to a checkbox because I don't think you can uncheck a radio button without selecting another one. Since you only have one...Once it's on, you're stuck.

<input type=&quot;checkbox&quot; name=&quot;shippingaddress&quot; onClick=&quot;chkMe()&quot;>

Here's the function I used, note there aren't any spaces in the field names, JS doesn't seem to like them.
Code:
function chkMe() {
  if (document.OrderingForm.shippingaddress.checked) {
    document.OrderingForm.ShippingName.value = document.OrderingForm.BillingName.value;
  }
}

Good luck!
 
Almost same logic but different way of implementing it :


<input type=&quot;checkbox&quot; name=&quot;shippingaddress&quot; onClick=&quot;chkMe(this)&quot;>

function chkMe(elm) {
if (elm.checked) {
document.OrderingForm.ShippingName.value = document.OrderingForm.BillingName.value;
}
else
{
document.OrderingForm.ShippingName.value = &quot;&quot;
}
}

This version of the function empties the shipping address if the user unselects the check box. Gary Haran
 
Hey don't worry about it!

First, change the first dept field from &quot;dept.&quot; to &quot;dept&quot;.

Then change your function to:
Code:
  <script language=&quot;javascript&quot;><!--
function chkMe(elm) {
  if (elm.checked) {
    document.OrderingForm.Name2.value = document.OrderingForm.Name.value;
    document.OrderingForm.Tel2.value = document.OrderingForm.Tel.value;
    document.OrderingForm.Fax2.value = document.OrderingForm.Fax.value;
    document.OrderingForm.Company2.value = document.OrderingForm.Company.value;
    document.OrderingForm.Dept2.value = document.OrderingForm.Dept.value;
    document.OrderingForm.Street2.value = document.OrderingForm.Street.value;
    document.OrderingForm.City2.value = document.OrderingForm.City.value;
    document.OrderingForm.State2.value = document.OrderingForm.State.value;
    document.OrderingForm.Zip2.value = document.OrderingForm.Zip.value;
    document.OrderingForm.Country2.value = document.OrderingForm.Country.value;
  }
  else   {
    document.OrderingForm.Name2.value = &quot;&quot;
    document.OrderingForm.Tel2.value = &quot;&quot;
    document.OrderingForm.Fax2.value = &quot;&quot;
    document.OrderingForm.Company2.value = &quot;&quot;
    document.OrderingForm.Dept2.value = &quot;&quot;
    document.OrderingForm.Street2.value = &quot;&quot;
    document.OrderingForm.City2.value = &quot;&quot;
    document.OrderingForm.State2.value = &quot;&quot;
    document.OrderingForm.Zip2.value = &quot;&quot;
    document.OrderingForm.Country2.value = &quot;&quot;
  }
}
//--></script>

The only thing technically wrong with your code, was the last } was really a parenthesis ) instead of a close squiggly bracket }. So, give this a try....

Also, you can keep the function in your first <script> section if you want, or you can keep it where it is.

Good luck! :)
 
I want to use something similar to this to automatically check a checkbox when a user either inputs data in a text box or changes data in a text box but I cant get it to work.

Any ideas?
 
[tt]Sibylle, I've awarded jlsmithprism a
star.gif
on your behalf because his post apparently was helpful. As courtesy, let's all try to do the same. Thanks

Simply an observation.
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
Thanks Tony :)

thysonj,

Try this...
Code:
<form name=&quot;myform&quot;>
<input type=checkbox name=wc_checkbox> Check Me<br>
<input type=text name=wt_text onchange=&quot;document.myform.wc_checkbox.checked = true;&quot;>
</form>
Hope this helps,
Jessica
[ponytails2]
 
[tt]

Sorry about my &quot;his post apparently was helpful&quot; comment.

A
star.gif
for her
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
nicly done TonyU! [thumbsup2] I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top