zaw wrote:
Hi I am working on implementing this script to shopping cart.
Basically, it copies fill the shipping address from billing
automatically. I believe one or more syntax is not netscape
compatible. Can anyone point out which one it is and how to make it
both netscape and MS browser compatible? I hope if I can make the
script compatible for those two at extreme, it will probably work with
most browser out there. As you would notice, this form also calls
another fundtion already implemented in the shopping cart. But that
function itself works on both browser.
It would make life considerably easier if you reduced your code to a
minimal example of the issue. Posting 50 lines of
document.getElementById() code means that to do anything useful,
someone must reverse engineer your HTML. The chances they will get it
the same as yours are pretty slim.
You also do not include the code for change_states(), a likely source
of error.
You pass as reference to the shipping details form when calling
CopyBill, so why not use it instead of document.getElementById? If you
also pass a reference to the billing form, you can get rid of it almost
entirely, e.g.
function CopyBill(form) {
...
document.getElementById("s_title").selectedIndex =
document.getElementById("title").selectedIndex;
becomes
function CopyBill(b,s) {
s.elements("s_title").selectedIndex=
b.elements("title").selectedIndex;
I reverse engineered the HTML and your code (sans change_states())
works fine in Netscape. So either I fixed the issues or they are in
the HTML.
As a rule, if you develop using Netscape/Firefox and use IE for testing,
you will have fewer issues with accessing the document - but like all
rules, it's made to be broken. Slabs of code below...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Copy form</title>
<script>
var s_titleIndex = 0;
var s_firstname = "";
var s_lastname = "";
var s_address = "";
var s_address_2 = "";
var s_city = "";
var s_zipcode = "";
var s_stateIndex = 0;
var s_countryIndex = 0;
var s_state = 0;
function SaveShipInfo(form) {
s_titleIndex = document.getElementById("s_title").selectedIndex;
s_firstname = document.getElementById("s_firstname").value;
s_lastname = document.getElementById("s_lastname").value;
s_address = document.getElementById("s_address").value;
s_address_2 = document.getElementById("s_address_2").value;
s_city = document.getElementById("s_city").value;
s_zipcode = document.getElementById("s_zipcode").value;
s_stateIndex = document.getElementById("_s_state").selectedIndex;
s_countryIndex = document.getElementById("s_country").selectedIndex ;
s_state = document.getElementById("_s_state").value;
}
function CopyBill(form) {
if (form.copybill.checked) {
SaveShipInfo(form);
document.getElementById("s_title").selectedIndex =
document.getElementById("title").selectedIndex;
document.getElementById("s_firstname").value =
document.getElementById("firstname").value;
document.getElementById("s_lastname").value =
document.getElementById("lastname").value;
document.getElementById("s_address").value =
document.getElementById("b_address").value;
document.getElementById("s_address_2").value =
document.getElementById("b_address_2").value;
document.getElementById("s_city").value =
document.getElementById("b_city").value;
document.getElementById("s_zipcode").value =
document.getElementById("b_zipcode").value;
document.getElementById("s_country").selectedIndex =
document.getElementById("b_country").selectedIndex ;
/*
change_states(document.getElementById('s_country') , 's_state',
's_county', 'State', 'CA', '', '', '','','');
*/
document.getElementById("_s_state").selectedIndex =
document.getElementById("_b_state").selectedIndex;
document.getElementById("s_state").value =
document.getElementById("_s_state").value;
}
else {
document.getElementById("s_title").selectedIndex = s_titleIndex;
document.getElementById("s_firstname").value = s_firstname;
document.getElementById("s_lastname").value = s_lastname;
document.getElementById("s_address").value = s_address;
document.getElementById("s_address_2").value = s_address_2;
document.getElementById("s_city").value = s_city;
document.getElementById("s_zipcode").value = s_zipcode;
document.getElementById("s_country").selectedIndex = s_countryIndex;
/*
change_states(document.getElementById('s_country') , 's_state',
's_county', 'State', 'CA', '', '', '','','');
*/
document.getElementById("_s_state").selectedIndex = s_stateIndex;
document.getElementById("s_state").value = s_state;
}
}
</script>
</head>
<body style="font-family: sans-serif; font-size: 8pt;">
<table><tr><td>
<p>Billing Details</p>
<form action="" id="billingform">
<p>
<select name="title" id="title">
<option value="Mr">Mr</option>
<option value="Mrs" selected>Mrs</option>
<option value="Ms">Ms</option>
</select>Title<br>
<input type="text" size="20" name="firstname"
id="firstname" value="Fred">First Name<br>
<input type="text" size="20" name="lastname"
id="lastname" value="Smith">Last Name<br>
<input type="text" size="20" name="b_address"
id="b_address" value="12 Smith St">Address 1<br>
<input type="text" size="20" name="b_address_2"
id="b_address_2" value="Smithville">Address 2<br>
<input type="text" size="20" name="b_city"
id="b_city" value="Smithtown">City<br>
<input type="text" size="20" name="b_zipcode"
id="b_zipcode" value="1234">Zip/Post code<br>
<select name="_b_state" id="_b_state">
<option value="NY">New York</option>
<option value="TX" selected>Texas</option>
<option value="FL">Florida</option>
</select>State<br>
<select name="b_country" id="b_country">
<option value="USA">United States of America</option>
<option value="UK" selected>United Kingdom</option>
<option value="AUS">Australia</option>
</select>Country<br>
<input type="checkbox" name="copybill" id="copybill"
checked>Copy bill<br>
<input type="reset">
</form>
</td>
<td valign="bottom">
<button value="copy" onclick="
CopyBill(document.getElementById('billingform'));
">Copy billing to shipping</button>
</td>
<td>
<p>Shipping Details</p>
<form action="" id="shippingform">
<p>
<select name="s_title" id="s_title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
</select>Title<br>
<input type="text" size="20" name="s_firstname"
id="s_firstname">First Name<br>
<input type="text" size="20" name="s_lastname"
id="s_lastname">Last Name<br>
<input type="text" size="20" name="s_address"
id="s_address">Address 1<br>
<input type="text" size="20" name="s_address_2"
id="s_address_2">Address 2<br>
<input type="text" size="20" name="s_city"
id="s_city">City<br>
<input type="text" size="20" name="s_zipcode"
id="s_zipcode">Zip/Post code<br>
<select name="_s_state" id="_s_state">
<option value="NY">New York</option>
<option value="TX">Texas</option>
<option value="FL">Florida</option>
</select>State<br>
<input type="text" name="s_state" id="s_state">State<br>
<select name="s_country" id="s_country">
<option value="USA">United States of America</option>
<option value="UK">United Kingdom</option>
<option value="AUS">Australia</option>
</select>Country<br>
<input type="reset">
</form>
</td></tr></table>
</body>
</html>
--
Rob