gigantorTRON
01-24-2008, 11:00 PM
I have javascript code as defined here:
<SCRIPT LANGUAGE="JavaScript">
//create onDomReady Event
window.onDomReady = DomReady;
//Setup the event
function DomReady(fn)
{
//W3C
if(document.addEventListener)
{
document.addEventListener("DOMContentLoaded", fn, false);
}
//IE
else
{
document.onreadystatechange = function(){readyState(fn)}
}
}
//IE execute function
function readyState(fn)
{
//dom is ready for interaction
if(document.readyState == "completed")
{
fn();
}
}
function hideStates(element, name)
{
if (name =='post_customer_Country')
{
if (element=='US' || element=='CA')
{
document.getElementById("state1").innerHTML = '<?php $HTML->print_StatesDorpDownBox("post_customer_State", "", $post_customer_State); ?>'
}
else
{
document.getElementById("state1").innerHTML='<input type="text" name="post_customer_State" id="post_customer_State_Text" size="15" maxlength="25" value="<?php print $post_customer_State; ?>">';
}
}
else
{
if (element=='US' || element=='CA')
{
document.getElementById("state2").innerHTML = '<?php $HTML->print_StatesDorpDownBox("post_members_State", "", $post_members_State); ?>'
}
else
{
document.getElementById("state2").innerHTML='<input type="text" name="post_members_State" id="post_members_State_Text" size="15" maxlength="25" value="<?php print $post_members_State; ?>">';
}
}
}
function onReady()
{
hideStates(document.getElementById('post_customer_Country').value, 'post_customer_Country');
hideStates(document.getElementById('post_members_Country').value, 'post_members_Country');
}
window.onDomReady(onReady);
</script>
Basically, this is a edit registration form containing country and state/province/region. If the United States or Canada is selected, a drop down box will appear for state. Otherwise, a text box will be displayed. However, I need the appropriate form element to be displayed upon loading which is what the onReady function is for. This works correctly in Firefox but not IE or Safari. I debugged in Safari and found no errors. I also ran the script through a JS validator.
:confused:
Thanks!
<SCRIPT LANGUAGE="JavaScript">
//create onDomReady Event
window.onDomReady = DomReady;
//Setup the event
function DomReady(fn)
{
//W3C
if(document.addEventListener)
{
document.addEventListener("DOMContentLoaded", fn, false);
}
//IE
else
{
document.onreadystatechange = function(){readyState(fn)}
}
}
//IE execute function
function readyState(fn)
{
//dom is ready for interaction
if(document.readyState == "completed")
{
fn();
}
}
function hideStates(element, name)
{
if (name =='post_customer_Country')
{
if (element=='US' || element=='CA')
{
document.getElementById("state1").innerHTML = '<?php $HTML->print_StatesDorpDownBox("post_customer_State", "", $post_customer_State); ?>'
}
else
{
document.getElementById("state1").innerHTML='<input type="text" name="post_customer_State" id="post_customer_State_Text" size="15" maxlength="25" value="<?php print $post_customer_State; ?>">';
}
}
else
{
if (element=='US' || element=='CA')
{
document.getElementById("state2").innerHTML = '<?php $HTML->print_StatesDorpDownBox("post_members_State", "", $post_members_State); ?>'
}
else
{
document.getElementById("state2").innerHTML='<input type="text" name="post_members_State" id="post_members_State_Text" size="15" maxlength="25" value="<?php print $post_members_State; ?>">';
}
}
}
function onReady()
{
hideStates(document.getElementById('post_customer_Country').value, 'post_customer_Country');
hideStates(document.getElementById('post_members_Country').value, 'post_members_Country');
}
window.onDomReady(onReady);
</script>
Basically, this is a edit registration form containing country and state/province/region. If the United States or Canada is selected, a drop down box will appear for state. Otherwise, a text box will be displayed. However, I need the appropriate form element to be displayed upon loading which is what the onReady function is for. This works correctly in Firefox but not IE or Safari. I debugged in Safari and found no errors. I also ran the script through a JS validator.
:confused:
Thanks!