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.getEle mentById() 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.getEle mentById? If you
also pass a reference to the billing form, you can get rid of it almost
entirely, e.g.
function CopyBill(form) {
...
document.getEle mentById("s_tit le").selectedIn dex =
document.getEle mentById("title ").selectedInde x;
becomes
function CopyBill(b,s) {
s.elements("s_t itle").selected Index=
b.elements("tit le").selectedIn dex;
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><ti tle>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(fo rm) {
s_titleIndex = document.getEle mentById("s_tit le").selectedIn dex;
s_firstname = document.getEle mentById("s_fir stname").value;
s_lastname = document.getEle mentById("s_las tname").value;
s_address = document.getEle mentById("s_add ress").value;
s_address_2 = document.getEle mentById("s_add ress_2").value;
s_city = document.getEle mentById("s_cit y").value;
s_zipcode = document.getEle mentById("s_zip code").value;
s_stateIndex = document.getEle mentById("_s_st ate").selectedI ndex;
s_countryIndex = document.getEle mentById("s_cou ntry").selected Index;
s_state = document.getEle mentById("_s_st ate").value;
}
function CopyBill(form) {
if (form.copybill. checked) {
SaveShipInfo(fo rm);
document.getEle mentById("s_tit le").selectedIn dex =
document.getEle mentById("title ").selectedInde x;
document.getEle mentById("s_fir stname").value =
document.getEle mentById("first name").value;
document.getEle mentById("s_las tname").value =
document.getEle mentById("lastn ame").value;
document.getEle mentById("s_add ress").value =
document.getEle mentById("b_add ress").value;
document.getEle mentById("s_add ress_2").value =
document.getEle mentById("b_add ress_2").value;
document.getEle mentById("s_cit y").value =
document.getEle mentById("b_cit y").value;
document.getEle mentById("s_zip code").value =
document.getEle mentById("b_zip code").value;
document.getEle mentById("s_cou ntry").selected Index =
document.getEle mentById("b_cou ntry").selected Index;
/*
change_states(d ocument.getElem entById('s_coun try'), 's_state',
's_county', 'State', 'CA', '', '', '','','');
*/
document.getEle mentById("_s_st ate").selectedI ndex =
document.getEle mentById("_b_st ate").selectedI ndex;
document.getEle mentById("s_sta te").value =
document.getEle mentById("_s_st ate").value;
}
else {
document.getEle mentById("s_tit le").selectedIn dex = s_titleIndex;
document.getEle mentById("s_fir stname").value = s_firstname;
document.getEle mentById("s_las tname").value = s_lastname;
document.getEle mentById("s_add ress").value = s_address;
document.getEle mentById("s_add ress_2").value = s_address_2;
document.getEle mentById("s_cit y").value = s_city;
document.getEle mentById("s_zip code").value = s_zipcode;
document.getEle mentById("s_cou ntry").selected Index = s_countryIndex;
/*
change_states(d ocument.getElem entById('s_coun try'), 's_state',
's_county', 'State', 'CA', '', '', '','','');
*/
document.getEle mentById("_s_st ate").selectedI ndex = s_stateIndex;
document.getEle mentById("s_sta te").value = s_state;
}
}
</script>
</head>
<body style="font-family: sans-serif; font-size: 8pt;">
<table><tr><t d>
<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">Fi rst Name<br>
<input type="text" size="20" name="lastname"
id="lastname" value="Smith">L ast 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="Smithvil le">Address 2<br>
<input type="text" size="20" name="b_city"
id="b_city" value="Smithtow n">City<br>
<input type="text" size="20" name="b_zipcode "
id="b_zipcode" value="1234">Zi p/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">Flor ida</option>
</select>State<br >
<select name="b_country " id="b_country" >
<option value="USA">Uni ted States of America</option>
<option value="UK" selected>United Kingdom</option>
<option value="AUS">Aus tralia</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(docume nt.getElementBy Id('billingform '));
">Copy billing to shipping</button>
</td>
<td>
<p>Shipping Details</p>
<form action="" id="shippingfor m">
<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_firstna me"
id="s_firstname ">First Name<br>
<input type="text" size="20" name="s_lastnam e"
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">Cit y<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">Texa s</option>
<option value="FL">Flor ida</option>
</select>State<br >
<input type="text" name="s_state" id="s_state">St ate<br>
<select name="s_country " id="s_country" >
<option value="USA">Uni ted States of America</option>
<option value="UK">Unit ed Kingdom</option>
<option value="AUS">Aus tralia</option>
</select>Country< br>
<input type="reset">
</form>
</td></tr></table>
</body>
</html>
--
Rob