views:

347

answers:

6
<script type="application/javascript" language="javascript">
    function showElement(elementID, show){
    var element = document.getElementById(elementID);
    if (element) {
      element.className = (show ? element.className.replace(/hidden/gi, "show") : element.className + " hidden");
     }
    }
</script>

        <table cellpadding="3" cellspacing="1" border="0" width="100%">  
            <tr class="baseGrayMedium">
                <td colspan="2">
                    (<a href="javascript:void(0);" onClick="showElement('evicChkLst',true);" class="nostyle">+</span></a>|<a href="javascript:void(0);" onClick="showElement('evicChkLst',false);" class="nostyle">-</span></a>) &nbsp;&nbsp; <B>Eviction Checklist</B>
                </td>
            </tr>
        </table>

i get the javascript error saying object expected and it points to onClick event in the HTML code.. Could some one suggest me why so

A: 

try prepending "javascript:" to the onclick event ("onclick" all lowercase is xhtml compliant btw).

marduk
A: 

No it didnt work though i prepended "javascript:" to the onclick event.. Any more suggestions ?

krishna
try to replace javascript:void(0) by #
Gregoire
A: 

Check that link

Gregoire
it didnt work either.. it shows the same object expected error. The code works fine in firefox though
krishna
any more suggestions... I replaced the javascript:void thing to #
krishna
yes i removed the void already and replaced it with #...I see the microsoft script editor pointing to the onclick event in debugging
krishna
See my other answer
Gregoire
A: 

I don't immediately see anything wrong in your snippet.

It's possible that formatting elsewhere in your script has messed up the definition or scope of showElement. Try adding this link next to the others:

<a href="javascript:void(0)" onclick="alert(typeof showElement);">?</a>

It should alert function if everything up to that point is good (or, at least, not alert undefined).

Jonathan Lonowski
ok it says undefined on clicking ?
krishna
what could be the reason?
krishna
+1  A: 

Your probelm is: <script type="application/javascript" language="javascript"> it must be <script type="text/javascript" language="javascript">

Gregoire
Thanksit worksi didnt see thatcool
krishna
A: 
function showElement(elementID, show){ var element = document.getElementById(elementID); if (element) { element.className = (show ? element.className.replace(/hidden/gi, "show") : element.className + " hidden"); } }
        <table cellpadding="3" cellspacing="1" border="0" width="100%">  
            <tr class="baseGrayMedium">
                <td colspan="2">
                    (<a href="#" onclick="javascript:showElement('evicChkLst',true);" class="nostyle">+</span></a>|<a href="#" onclick="javascript:showElement('evicChkLst',false);" class="nostyle">-</span></a>) &nbsp;&nbsp; <B>Eviction Checklist</B>

    </td>
            </tr>
        </table>

now the code looks some thing like the above

krishna
This might be better as an edit to your question -- this definitely isn't an answer on its own.
Jonathan Lonowski

related questions