Link to home
Start Free TrialLog in
Avatar of MulyCat
MulyCat

asked on

Javascript form validation works in I.e., not safari or firefox

I have an asp.net application where I use a javascript file to validate the form entries (basic bill to ship to info). The .js file utilizes the class object for its tpe validation. I have created clientid's in my code and I create an array of required fields and a companion text map to populate an alert message string. All works well in I.E. In Safari the code stops working once I define the arrays. I am quite stumped. Any help would be appreciated. Code attached, sorry my own comments were not edited out - Please be kind!! This is my bosses account, so please do not hold it against him..

Thanks :)

 
// For a more flexible event registration routine, see
 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}
 
addLoadEvent(attachFormHandlers());
addLoadEvent(function() {
  /* more code to run on page load */ 
 
 
});
function attachFormHandlers()
{
  // Ensure we're working with a 'relatively' standards 
  // compliant browser
  if (document.getElementsByTagName)
  {
 
    var objForm = window.document.getElementsByTagName('form');
    
    //objForm.innerHTML = objForm.innerHTML;
    for (var iCounter=0; iCounter<objForm.length; iCounter++)
      objForm[iCounter].onsubmit = function(){return formCheck(this);};
  }
}
function formCheck(formobj){
 
 
	// Enter name of mandatory fields
    //var fieldRequired = new Array();
   var objForm = window.document.form1.elements;
    
   if (window.document.form1.shipbilltosame.checked)
   {
	    
   //Same Bill To Ship To
	    var country = countryID.options(countryID.selectedIndex).text;
	// COUNTRY United States or Canada
	        if(country == "United States" || country == "Canada")
	        {
	        //state drop down 
	            var state = stateID.options(stateID.selectedIndex).text;
	            if (state == "- Canadian Provinces -" || state == "- US States -" || state == "Select State / Province")
	            {
	            alert ("Please select from the Bill To State Drop Down");
	            return false;
	    
	            }
    //alert ("hey " + country);
	            //var fieldRequired = Array(firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id);
	            var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id];
	// Enter field description to appear in the dialog box
	            var fieldDescription = ["First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country"];
	        }
	// COUNTRY NOT United States or Canada
	        else
	        {
	            var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id];
	// Enter field description to appear in the dialog box
	            var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country"];
	//alert ("hey international" + country);
	        }
	// dialog message
	}
	else
	{
   //Different Bill To Ship To
	    //var country = countryID.options(countryID.selectedIndex).text;
	    var shipcountry = ship_countryID.options(ship_countryID.selectedIndex).text;
	     if (shipcountry == "Select Country")
	     {
	    alert ("Please make a selection from the Ship To Country or check the Ship To Same Box");
	    return false;
	    
	    }
	// COUNTRY United States or Canada
	        if (country === "United States" || country === "Canada")
	            {var BC = "dd";}
	        else
	           {var BC = "nd";}
	        
	        if (shipcountry === "United States" || shipcountry === "Canada")
	            {var SC = "dd";}
	        else
	            {var SC = "nd";}
	        //alert ("hey SC "+ SC + "BC " + BC);
	            
	            if (BC === "dd" && SC === "dd")
	                {
    //alert ("hey " + country);
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_cityID.id, ship_stateID.id, ship_zipID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To City", "Ship To State", "Ship To Zip", "Ship To Phone", "Ship To Country"];
	                }
	                
	// COUNTRY NOT United States or Canada
	            if (BC === "nd" && SC === "nd")
	                {
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To Phone", "Ship To Country"];
	//alert ("hey international" + country);
	                }
	                
	            if (BC === "dd" && SC === "nd")
	                {
    //alert ("hey " + country);
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To Phone", "Ship To Country"];
	                }
	                
	// COUNTRY NOT United States or Canada
	            if (BC === "nd" && SC === "dd")
	                {
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_cityID.id, ship_stateID.id, ship_zipID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To City", "Ship To State", "Ship To Zip", "Ship To Phone", "Ship To Country"];
	
	                }
	                
	// dialog message
	}
	var alertMsg = "Please complete the following fields:\n";
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
	var obj = objForm.elements[fieldRequired[i]];
	
			if (obj){
			switch(obj.className){
			//switch(obj.type){
			//case "select-one":
			case "select-one":
				if (obj.selectedIndex === -1 || obj.options[obj.selectedIndex].value === "" || obj.options[obj.selectedIndex].value === null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			//case "textarea":
				if (obj.value === "" || obj.value === null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
				case "email":
			//case "email":
				
					var x = obj.value;
	                var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	                if (!filter.test(x)){ //break;//alert('YES! Correct email address');
	                //else alertMsg += " - " + fieldDescription[i] + "\n";
	                alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "numeric":
			    
				if (obj.value === "" || obj.value === null || isNaN(obj.value)){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex === -1 || obj.options[obj.selectedIndex].value === "" || obj.options[obj.selectedIndex].value === null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
				default:
			}
			//if (obj.type == undefined){
			if (obj.className === undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
 
 
	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
 
// -->

Open in new window

Avatar of mespinozae
mespinozae
Flag of Costa Rica image

Wouldnt it be easier to add ids to the objects and have a somewhat generic function to call onSubmit, have this function check for the input and compliances?

Hate to say this but Internet Explorer isnt too standards compliant so if it is only working in IE there is something wrong in your code. Check the http://w3.org for ways to proceed, they have a validator there that should help you tidy your code up
Avatar of b0lsc0tt
Thanks for the javascript but that alone doesn't help much.  If you are getting an error on a specific line then let us know that error and the code on that line.

If you don't get an error then provide the html source and  the script.  Please make sure it is the html source and not the server script.

If you want a general suggestion based on what you mentioned make sure your form fields don't just use id attributes.  If you are trying to use document.form.elementName to access the fields they need to have name attributes too.  IE will treat the ID as a name value if the later is missing but other browsers don't.

I didn't notice anything wrong with the script I saw but it is hard to find a problem without an idea of where to look for the needle in the haystack. :)

bol
Avatar of MulyCat
MulyCat

ASKER

Thanks for your reply

I have included the html code. You will notice I do use a disable function that is the result of an onchange event. This works in Safari, but the FieldRequired strings do not. The Check the bill to ship to same box also works in Safari. None of this works in FireFox.  Notice the script for the ID fields.

<asp:PlaceHolder enableviewstate="false" ID="PlaceHolder1" runat="server" >
<center><div id="Pubcustomer"  style="color:black; border-style:solid; border-width:medium; background:LightGoldenrodYellow; top:0; width: 700px; height: 1100px; margin: 0 0 0 75px; font-style:italic; font-weight:bold; font-family:Arial">
 
     <table style="width:650px; vertical-align:top"><tr>
       <td>
     <table style="vertical-align:top">
  <tr></tr>   
<tr><td align="center"><b>Billing Information</b></td></tr>
<tr><td style="height: 10px;"></td></tr> 
<tr><td align="left"><span style="color:Red">**</span> First Name : </td></tr>
<tr><td align="center"><input name="firstname" id="firstname" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"><span style="color:Red">**</span> Last Name : </td></tr>
<tr><td align="center"><input name="lastname" id="lastname" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"><span style="color:Red">**</span> First Address Line : </td></tr>
<tr><td align="center"><input name="address1" id="address1" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"> Address : </td></tr>
<tr><td align="center"><input name="address2" id="address2" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"><span style="color:Red">**</span> Country: </td></tr>
<tr><td> 
 
 
      <asp:DropDownList id="billCountrySelect" runat="server" AutoPostBack="false" OnChange="javascript:SetCountryFields();"> 
<asp:ListItem Value="">Select Country</asp:ListItem> 
<asp:ListItem Value="AF">Afghanistan</asp:ListItem> 
deleted rows here
<asp:ListItem Value="ZM">Zambia</asp:ListItem> 
<asp:ListItem Value="ZW">Zimbabwe</asp:ListItem> 
</asp:DropDownList></td></tr>
<tr><td align="left"><span style="color:Red">**</span> City : </td></tr>
<tr><td align="center"><input name="city" id="city" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
 
<tr><td align="left"><span style="color:Red">**</span> State US Canada: </td></tr><tr><td>
         <asp:DropDownList id="billStateSelect"  runat="server">
<asp:ListItem Value="">Select State / Province</asp:ListItem>
<asp:ListItem Value="">- US States -</asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
deleted rows here
<asp:ListItem Value="SK">Saskatchewan</asp:ListItem>
<asp:ListItem Value="YT">Yukon</asp:ListItem>
</asp:DropDownList>
 
</td></tr>
<tr><td align="left"><span style="color:Red">**</span> Zip : </td></tr>
<tr><td align="center"><input name="zip" id="zip" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left" style="font-size:smaller">Countries other than US or Canada</td></tr>
<tr><td align="left" style="font-size:smaller">use the above 2 address fields</td></tr>
<tr><td align="left" style="font-size:smaller">and the additional fields below,</td></tr>
<tr><td align="left" style="font-size:smaller">rather than city, state or zip</td></tr>
<tr><td align="left" style="font-size:smaller">Note: The First Name, Last Name and </td></tr>
<tr><td align="left" style="font-size:smaller">First Address Line above required.</td></tr>
<tr><td align="center"><input name="address3" id="address3" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="center"><input name="address4" id="address4" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="center"><input name="address5" id="address5" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left">** Email Address : </td></tr>
<tr><td align="center"><input name="email_address" id="email_address" runat="server" class="email" type="text" value="" size="25" maxlength="100" /></td></tr>
<tr><td align="left">** Phone : </td></tr>
<tr><td align="center"><input name="phone" id="phone" runat="server" class="text" type="text" value="" size="25" maxlength="50" />
</td></tr></table>
 </td> 
 
 <td>
 <table style="vertical-align:top">
<tr><td align="center"><b>Shipping Information</b></td></tr>
<tr><td style="height: 10px;"></td></tr>
<tr><td align="left"><span style="color:Red">**</span> First Name : </td></tr>
<tr><td align="center"><input id="ship_firstname" runat="server" name="ship_firstname" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"><span style="color:Red">**</span> Last Name : </td></tr>
<tr><td align="center"><input name="ship_lastname" id="ship_lastname" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"><span style="color:Red">**</span> First Address Line : </td></tr>
<tr><td align="center"><input name="ship_address1" id="ship_address1" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left"> Address : </td></tr>
<tr><td align="center"><input name="ship_address2" id="ship_address2" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
    
<tr><td align="left"><span style="color:Red">**</span> Country: </td></tr><tr><td> 
      <asp:DropDownList id="shipCountryselect" runat="server" AutoPostBack="false" OnChange="javascript:SetShipCountryFields();"> 
<asp:ListItem Value="">Select Country</asp:ListItem> 
<asp:ListItem Value="AF">Afghanistan</asp:ListItem> 
deleted rows here
<asp:ListItem Value="ZM">Zambia</asp:ListItem> 
<asp:ListItem Value="ZW">Zimbabwe</asp:ListItem> 
</asp:DropDownList></td></tr>
<tr><td align="left"><span style="color:Red">**</span> City : </td></tr>
<tr><td align="center"><input name="ship_city" id="ship_city" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
 
<tr><td align="left"><span style="color:Red">**</span> State US Canada: </td></tr><tr><td>
         <asp:DropDownList id="shipStateselect" runat="server">
<asp:ListItem Value="">Select State / Province</asp:ListItem>
<asp:ListItem Value="U">- US States -</asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
deleted rows here
<asp:ListItem Value="QC">Quebec</asp:ListItem>
<asp:ListItem Value="SK">Saskatchewan</asp:ListItem>
<asp:ListItem Value="YT">Yukon</asp:ListItem>
</asp:DropDownList>
 
</td></tr>
<tr><td align="left"><span style="color:Red">**</span> Zip : </td></tr>
<tr><td align="center"><input name="ship_zip" id="ship_zip" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="left" style="font-size:smaller">Countries other than US or Canada</td></tr>
<tr><td align="left" style="font-size:smaller">use the above 2 address fields</td></tr>
<tr><td align="left" style="font-size:smaller">and the additional fields below</td></tr>
<tr><td align="left" style="font-size:smaller">rather than city, state or zip</td></tr>
<tr><td align="left" style="font-size:smaller">Note: The First Name, Last Name and </td></tr>
<tr><td align="left" style="font-size:smaller">First Address Line above required.</td></tr>
<tr><td align="center"><input name="ship_address3" id="ship_address3" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="center"><input name="ship_address4" id="ship_address4" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
<tr><td align="center"><input name="ship_address5" id="ship_address5" runat="server" class="text" type="text" value="" size="25" maxlength="50" /></td></tr>
 
<tr><td align="left">Phone : </td></tr>
<tr><td align="center"><input name="ship_phone" id="ship_phone" runat="server" class="text" type="text" value="" size="25" maxlength="50" />
</td></tr>
<tr><td style="height: 48px;"></td></tr></table>
     </td>
     </tr>
     </table>
      <br/>
      <p>&nbsp&nbsp&nbsp Billing Address must be the credit card holders address!</p>
      <p>&nbsp&nbsp&nbsp<span style="color:Red">** Indicates Required Field for US and Canada</span></p>
      &nbsp&nbsp&nbsp<input id="shipbilltosame" name="shipbilltosame" type="checkbox" />
      &nbsp Click here if Bill To and Ship To will be the same 
      <br/><br/><p style="font-size: small; font-weight:normal; font-style:normal">
      &nbsp&nbsp&nbsp Orders shipped within the United States have no shipping charges.<br/>
      &nbsp&nbsp&nbsp International shipping charges are calculated as follows:<br/><br/>
      &nbsp&nbsp&nbsp Canada/Mexico @ $10.00 per year for each subscription<br/>
      &nbsp&nbsp&nbsp Other International @ $20.00 per year for each subscription<br/>
      <br/></p>
       <center><asp:Button ID="TotalPubs3" visible="false" runat ="server" font-bold="true" OnClick="button3" Text="Submit Subscription Order"/></center>
     
     <asp:Literal ID="Literal2" runat="server"></asp:Literal>
     <br/><br/>
</div></center></asp:PlaceHolder>
 
at the bottom of the code I have
 
this 
 
<script type="text/javascript" language="javascript">  
 
 
   var firstnameID = document.getElementById('<%= firstname.ClientID %>');
  firstnameID.className="text";
  var lastnameID = document.getElementById('<%= lastname.ClientID %>');
  lastnameID.className="text";
  var address1ID = document.getElementById('<%= address1.ClientID %>');
  address1ID.className="text";
  var address2ID = document.getElementById('<%= address2.ClientID %>');
  address2ID.className="text";
  var stateID = document.getElementById('<%= billStateSelect.ClientID %>');
  var cityID = document.getElementById('<%= city.ClientID %>');
  cityID.className="text";
  var zipID = document.getElementById('<%= zip.ClientID %>');
  zipID.className="text";
  var email_addressID = document.getElementById('<%= email_address.ClientID %>');
  email_addressID.className="email";
  var phoneID = document.getElementById('<%= phone.ClientID %>');
  phoneID.className="text";
  var countryID = document.getElementById('<%= billCountrySelect.ClientID %>');
  
  var ship_firstnameID = document.getElementById('<%= ship_firstname.ClientID %>');
  ship_firstnameID.className="text";
  var ship_lastnameID = document.getElementById('<%= ship_lastname.ClientID %>');
  ship_lastnameID.className="text";
  var ship_address1ID = document.getElementById('<%= ship_address1.ClientID %>');
  ship_address1ID.className="text";
  var ship_address2ID = document.getElementById('<%= ship_address2.ClientID %>');
  ship_address2ID.className="text";
  var ship_stateID = document.getElementById('<%= shipStateSelect.ClientID %>');
  var ship_cityID = document.getElementById('<%= ship_city.ClientID %>');
  ship_cityID.className="text";
  var ship_zipID = document.getElementById('<%= ship_zip.ClientID %>');
  ship_zipID.className="text";
  var ship_phoneID = document.getElementById('<%= ship_phone.ClientID %>');
  ship_phoneID.className="text";
  var ship_countryID = document.getElementById('<%= shipCountrySelect.ClientID %>');
  
  function SetCountryFields()
{
var country = document.getElementById('<%=billCountrySelect.ClientID %>');
var selectedcountry = country.options(country.selectedIndex).text;
if (selectedcountry == 'United States' || selectedcountry == 'Canada'){
var mystring = 'disabled'
var myaddress3 = document.getElementById('<%=address3.ClientID %>');
myaddress3.setAttribute("disabled", "true");
myaddress3.setAttribute("value", mystring);
var myaddress4 = document.getElementById('<%=address4.ClientID %>');
myaddress4.setAttribute("disabled", "true");
myaddress4.setAttribute("value", mystring);
var myaddress5 = document.getElementById('<%=address5.ClientID %>');
myaddress5.setAttribute("disabled", "true");
myaddress5.setAttribute("value", mystring);
var mystring = ''
var city = document.getElementById('<%=city.ClientID %>');
city.removeAttribute("disabled", "true");
city.setAttribute("value", mystring);
var zip = document.getElementById('<%=zip.ClientID %>');
zip.removeAttribute("disabled", "true");
zip.setAttribute("value", mystring);
var state = document.getElementById('<%=billStateSelect.ClientID %>');
state.options(state.selectedIndex).value = state.value;//'<%=Session("state") %>';
state.options.removeAttribute("disabled", "true")
//alert('selected shipcountry is : ' + selectedshipcountry);
 
//var state = document.getElementById('<%=billStateSelect.ClientID %>');
//state.SelectedItem.Value = "Pennsylvania"'<%=Session("state")%>'
//state.SelectedItem.Value.Selected = "True"
//state.options(state.selectedIndex).text == "PA"
//state.options(state.selectedIndex).value == "Pennsylvania"
 
//state.options(state.selectedIndex).value = Session("state") //state.value;//'<%=Session("state") %>';
//alert('The state is : ' + state.value);
//state.options.removeAttribute("disabled", "true")
//alert('selected country is : ' + selectedcountry);
}
else
{
var mystring = ''
var myaddress3 = document.getElementById('<%=address3.ClientID %>');
myaddress3.removeAttribute("disabled", "true");
myaddress3.setAttribute("value", mystring);
var myaddress4 = document.getElementById('<%=address4.ClientID %>');
myaddress4.removeAttribute("disabled", "true");
myaddress4.setAttribute("value", mystring);
var myaddress5 = document.getElementById('<%=address5.ClientID %>');
myaddress5.removeAttribute("disabled", "true");
myaddress5.setAttribute("value", mystring);
var mystring = 'disabled'
var city = document.getElementById('<%=city.ClientID %>');
city.setAttribute("disabled", "true");
city.setAttribute("value", mystring);
var zip = document.getElementById('<%=zip.ClientID %>');
zip.setAttribute("disabled", "true");
zip.setAttribute("value", mystring);
var state = document.getElementById('<%=billStateSelect.ClientID %>');
state.options(state.selectedIndex).value == "";
state.options.setAttribute("disabled", "true")
//alert('selected country is : ' + selectedcountry)
}
}
 
 
function SetShipCountryFields()
{
var shipcountry = document.getElementById('<%=shipCountrySelect.ClientID %>');
var selectedshipcountry = shipcountry.options(shipcountry.selectedIndex).text;
if (selectedshipcountry == 'United States' || selectedshipcountry == 'Canada'){
var mystring = 'disabled'
var myshipaddress3 = document.getElementById('<%=ship_address3.ClientID %>');
myshipaddress3.setAttribute("disabled", "true");
myshipaddress3.setAttribute("value", mystring);
var myshipaddress4 = document.getElementById('<%=ship_address4.ClientID %>');
myshipaddress4.setAttribute("disabled", "true");
myshipaddress4.setAttribute("value", mystring);
var myshipaddress5 = document.getElementById('<%=ship_address5.ClientID %>');
myshipaddress5.setAttribute("disabled", "true");
myshipaddress5.setAttribute("value", mystring);
var mystring = ''
var shipcity = document.getElementById('<%=ship_city.ClientID %>');
shipcity.removeAttribute("disabled", "true");
shipcity.setAttribute("value", mystring);
var shipzip = document.getElementById('<%=ship_zip.ClientID %>');
shipzip.removeAttribute("disabled", "true");
shipzip.setAttribute("value", mystring);
var shipstate = document.getElementById('<%=shipStateSelect.ClientID %>');
shipstate.options(shipstate.selectedIndex).value = shipstate.value;//'<%=Session("state") %>';
shipstate.options.removeAttribute("disabled", "true")
//alert('selected shipcountry is : ' + selectedshipcountry);
}
else
{
var mystring = ''
var myshipaddress3 = document.getElementById('<%=ship_address3.ClientID %>');
myshipaddress3.removeAttribute("disabled", "true");
myshipaddress3.setAttribute("value", mystring);
var myshipaddress4 = document.getElementById('<%=ship_address4.ClientID %>');
myshipaddress4.removeAttribute("disabled", "true");
myshipaddress4.setAttribute("value", mystring);
var myshipaddress5 = document.getElementById('<%=ship_address5.ClientID %>');
myshipaddress5.removeAttribute("disabled", "true");
myshipaddress5.setAttribute("value", mystring);
var mystring = 'disabled'
var shipcity = document.getElementById('<%=ship_city.ClientID %>');
shipcity.setAttribute("disabled", "true");
shipcity.setAttribute("value", mystring);
var shipzip = document.getElementById('<%=ship_zip.ClientID %>');
shipzip.setAttribute("disabled", "true");
shipzip.setAttribute("value", mystring);
var shipstate = document.getElementById('<%=shipStateSelect.ClientID %>');
shipstate.options(shipstate.selectedIndex).value == ""//text = 'Select State / Province';
shipstate.options.setAttribute("disabled", "true")
//alert('selected shipcountry is : ' + selectedshipcountry)
}
}
 
 
</script> 
     

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MulyCat
MulyCat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial