Click to See Complete Forum and Search --> : getElementById and Firefox


tito
08-31-2008, 09:03 PM
I am using this code to show/hide a table depending on an option selected. It works fine in IE but will not in FF. In FF, when you switch back to the option.value 'px' the table will not show

function switchit(id)
{

if (document.getElementById('mytemplate').options.value == 'px')
{
document.getElementById(id).style.display = '';
} else {
document.getElementById(id).style.display = 'none';
}

}


Can someone help me please?

HalfaBee
08-31-2008, 09:59 PM
It works for me, check in the FF error console, you might have an error somewhere.

tito
08-31-2008, 11:22 PM
Thank you for your reply. I get

Warning: Empty string passed to getElementById().

HalfaBee
08-31-2008, 11:32 PM
are you calling the switch() function with a value?
Not sure if switch is a good name for a function as there is already a builtin switch function.

tito
08-31-2008, 11:42 PM
I just changed the function name into changeme with no luck

I am calling the function like this with another function

<select id=\"mytemplate\" name=\"template\"
onChange=\"changeme('customtemplate');change(this);\">

and the table I want to hide

<table id=\"customtemplate\"

HalfaBee
08-31-2008, 11:46 PM
put alert( id ) in the function to see what is being passed, it looks ok.

tito
08-31-2008, 11:53 PM
Aha ... 'customtempate' from the second function is being passed, not 'mytemplate'

here is the fullcode

<script language="javascript">

function changeme(id)
{

if (document.getElementById('mytemplate').options.value == 'px')
{
document.getElementById(id).style.display = '';
}

else {
document.getElementById(id).style.display = 'none';
}
alert( id );
}
</script>

<SCRIPT LANGUAGE="JavaScript"> <!--
function change(what)
{
value = what.options[what.selectedIndex].value;
if (value != '')
if (document.templates)
document.templates.src = ("/development/templates/" + value + ".jpg");
}
//--> </SCRIPT>

and the select box

<select id=\"mytemplate\" name=\"template\"
onChange=\"changeme('customtemplate');change(this);\">

What I am doing is hiding a table with some elements and display an image of a template instead. And I want to go back into displaying the table when the option 'px' is selected. Works fine in IE but not in FF 3.01

tito
09-01-2008, 12:46 AM
I got confused a minute. 'customtemplate' is correct, but it just does not change it

tito
09-01-2008, 12:51 AM
no alert in firefox but good on ie

if (document.getElementById( 'mytemplate' ).options.value == 'px')
{alert (id);
document.getElementById( id ).style.display = '';

}

HalfaBee
09-01-2008, 12:57 AM
maybe document.getElementById( 'mytemplate' ).options.value is not being set to px in firefox

You need to debug. :)

tito
09-01-2008, 02:01 AM
Phew! I got it working in both browsers by removing 'options.'

(document.getElementById( 'mytemplate' ).value == 'pixel')