checkbox problems?

R

Rabel

I have a shopping cart that I am having a few problems with. I am
mostly a flash developer with basic if not little javascript knowledge,
I need for my checkout to have a checkbox that if clicked on will
populate my shipping addresses with my billing addresses, I have this
somewhat working with a code I got off of here thats like this

<script>
function copy(checked, source, target) {
if (checked) {
target.value = source.value
} else {
target.value = '';
}
}
</script>
//then like this in the form
<input type=checkbox onClick="copy(this.checked, this.form.bname,
this.form.sname)">

but the problem with that is that I have to put a checkbox with its own
code on each part of the form. I would like to have one that would
then populate the whole form. The other question I have is I need to
have a validate script from the form, the fields are

Name-text
address-text
city-text
state-select
zip-text
country-selected US
Phone-text
email-text

credit card number-text- just need it to check if its numbers and over
12

Any help is greatly appreciated, thanks in advance
 
R

Rabel

You are an idiot duncan, I did ask a question, and I was only asking
for help I believe I said
'Any HELP is greatly appreciated, thanks in advance'
but you decided that I knew what I was doing and suggested 'so do it'
well thanks man you were a lot of help. Who sits there and complains
about someones question anyway, get a life.

For everyone else out there who may have the same problem this is what
I used to solve it

<script>
function doit(obj,name,address,cityv,statev,zipcode)
{
if(obj.checked)
{
document.frm.elements[name].value = document.frm.bname.value
document.frm.elements[address].value = document.frm.baddr1.value
document.frm.elements[cityv].value = document.frm.bcity.value
document.frm.elements[statev].value = document.frm.bstate.value
document.frm.elements[zipcode].value = document.frm.bzip.value
}
else
{
document.frm.elements[name].value = ""
document.frm.elements[address].value = ""
document.frm.elements[cityv].value = ""
document.frm.elements[statev].value = ""
document.frm.elements[zipcode].value = ""
}
}
function validate()
{
var frm = document.frm

if(frm.bname.value == "" )
{
alert("Please enter valid billing first and last name");
return false;
}
if(frm.sname.value == "" )
{
alert("Please enter valid shipping first and last name");
return false;
}
if(frm.baddr1.value == "" )
{
alert("Please enter valid billing address");
return false;
}
if(frm.saddr1.value == "" )
{
alert("Please enter valid shipping address");
return false;
}
if(frm.bcity.value == "")
{
alert("Please enter valid billing city");
return false;
}
if(frm.scity.value == "")
{
alert("Please enter valid shipping city");
return false;
}
if(isNaN(frm.bzip.value) || (frm.bzip.value.length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.szip.value) || (frm.szip.value.length != 5 ))
{
alert("Please enter a valid zip code");
return false;
}
if(isNaN(frm.cardnumber.value) || frm.cardnumber.value.length <13)
{
alert("Please enter valid creditcard number");
return false;
}
if(isNaN(frm.phone.value) || frm.phone.value.length <10)
{
alert("Please enter a valid telephone number");
return false;
}
if(trimit(frm.email.value) != "")
{
return emailTest(frm.email)

}
}
function emailTest(obj){
reg=
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (!reg.test(obj.value) ){
alert('Invalid email address')
obj.focus()
return false;
}
}

function trimit(strInput)
{
return strInput.replace(/^\s*/,"").replace(/\s*$/,"");

}


</script>
//in the form tag
onsubmit="return validate()
//then on the checkbox
<input type = "checkbox" name = "chk" onclick =
"doit(this,'sname','saddr1','scity','sstate','szip');">

Hope that helps
 
T

Thomas 'PointedEars' Lahn

Rabel said:
You are an idiot duncan,

I don't like several people here either, however with me
there is enough courtesy left to refrain from such.
I did ask a question, and I was only asking for help

Does not matter anymore. Go away, please.
[...]
For everyone else out there who may have the same problem this is what
I used to solve it

It is not Valid (X)HTML, it is highly inefficient and it is flawed.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top