getElementById does not work on optgroup in IE 7?

This is a discussion on "getElementById does not work on optgroup in IE 7?" within the JavaScript Forum section. This forum, and the thread "getElementById does not work on optgroup in IE 7? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 28th, 2008, 23:11
Up'n'Coming Member
Join Date: Jun 2006
Location: Florida
Age: 29
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
getElementById does not work on optgroup in IE 7?

I do not know Javascript that well so I do not know if I am going about this the wrong way. Any help would be appreciated.

This function attempts to hide the options inside of the optgroup tag of the second select box based on the user selected option of the first select box. It works fine in Mozilla but IE7 still shows all the optgroups in the second select box. The idea is to show the appropriate list of states based on what country a user selects without reloading the page.

You can see a sample of the form here:
http://www.allacparts.com/testjs.php

The optgroup tags have an id of ctyCAN and ctyUSA.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>

<link rel="stylesheet" href="/css/form.css" type="text/css" media="all" />


<script type="text/javascript">
<!--
function showhideship() {

if (document.getElementById('country').value == "") {
document.getElementById('statewrap').style.display = "none";
document.getElementById('zipcodewrap').style.display = "none";
document.getElementById('stateotherwrap').style.display = "none";
document.getElementById('countryotherwrap').style.display = "none";
}
else if (document.getElementById('country').value == "223") {
document.getElementById('statewrap').style.display = "block";
document.getElementById('ctyCAN').style.display = "none";
document.getElementById('ctyUSA').style.display = "block";
document.getElementById('zipcodewrap').style.display = "block";
document.getElementById('stateotherwrap').style.display = "none";
document.getElementById('countryotherwrap').style.display = "none";
}
else if (document.getElementById('country').value == "38") {
document.getElementById('statewrap').style.display = "block";
document.getElementById('ctyCAN').style.display = "block";
document.getElementById('ctyUSA').style.display = "none";
document.getElementById('zipcodewrap').style.display = "block";
document.getElementById('stateotherwrap').style.display = "none";
document.getElementById('countryotherwrap').style.display = "none";
}
else if (document.getElementById('country').value == "other") {
document.getElementById('statewrap').style.display = "none";
document.getElementById('zipcodewrap').style.display = "block";
document.getElementById('stateotherwrap').style.display = "block";
document.getElementById('countryotherwrap').style.display = "block";
}
else {
document.getElementById('statewrap').style.display = "block";
document.getElementById('zipcodewrap').style.display = "block";
document.getElementById('stateotherwrap').style.display = "block";
document.getElementById('countryotherwrap').style.display = "block";
}

}
//-->
</script>
</head>

<body onload="showhideship();">

<form method='post' action='/process/get-shipping.php?mode=1' name='shipquote' id='shipquote' class='shipquoteform'>

<p id="countrywrap">
<label for="country">Country: </label>
<select id="country" name="country" onchange="showhideship();">
<option value="">First Select Your Country</option>
<option value="38">Canada</option>
<option value="223">United States</option>
<option value="other">Other</option>
</select>
</p>

<p id="statewrap">
<label for="state">State: </label>
<select id="state" name="state">

<option value="">Then Select Your State</option>
<optgroup label="Canada" name="ctyCAN" id="ctyCAN">
<option value="66">Alberta</option>
<option value="67">British Columbia</option>
<option value="68">Manitoba</option>
</optgroup>

<optgroup label="United States" name="ctyUSA" id="ctyUSA">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="4">Arizona</option>
</optgroup>

</select>
</p>

<p id="countryotherwrap">
<label for="countryother">Country:</label>
<input type='text' id="countryother" name="countryother" value='' size="23" />
</p>

<p id="stateotherwrap">
<label for="stateother">State:</label>
<input type='text' id="stateother" name="stateother" value='' size="23" />
</p>

<p id="zipcodewrap">
<label for="zipcode">Zip Code:</label>
<input type='text' id="zipcode" name="zipcode" value='' size="8" />
</p>

</form>
</body>
</html>
Thanks for any help you can provide.
Reply With Quote

Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help using document.getElementById jonnymorris JavaScript Forum 3 Mar 28th, 2008 22:52
Javascript menu - does not work on title page, but does work on other pages Crystal Phoenix Starting Out 4 Mar 24th, 2008 19:40
getelementbyid not working in IE6 or 7 trandrus JavaScript Forum 0 Aug 17th, 2007 23:01
document.getElementById is not working in Mozilla Firefox dhineraj JavaScript Forum 3 Jul 20th, 2007 02:31
window.opener.document["nameForm"].getElementById("someid").value; doesnt work drpompeii JavaScript Forum 0 Feb 17th, 2007 23:09


All times are GMT. The time now is 10:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43