I am desperately trying to get the Javascript on my billing/shipping form correct, but I am still having a brain-block when it comes to Javascript principles. It's difficult to remember what you need and where, especially when starting from the beginning. Right now my form is just showing the values associated with each field - I am trying to get one field to copy over to another without naming out every variable. I don't think I'm going about this the right way, so I'll probably start over.
Also, I can't remember what (i=0; i < formEl.billing.length; i++) means exactly.
My code:
//will first determine value of checkbox, true or false - check = true or check=false
function validateForm() {
var formEl = document.getElementById("billing_form");
var selectedCheck = copyOver();
return false;
}
function copyOver() {
var formEl = document.getElementById("billing_form");
for (i=0; i < formEl.billing.length; i++) {
if (formEl.checkme.checked) {
formEl.shipping[i].value = formEl.billing[i].value;
}
else { //if false, then leave blank
formEl.shipping[i].value = "";
}
}
}
//code Submit button
Grades
16 years ago
2 comments:
Joanna, I am still struggling with it too and have just been doing as many tutorials as possible. So, I don't have an answer for the form, but I believe this code: (i=0; i < formEl.billing.length; i++)
will increase the value of i by 1 until it equals the number of characters in the form element.
Larry,
I think you are right - I figured out soon after that this was not the code I was looking for. Thank you for your help!
Post a Comment