admin管理员组

文章数量:1289741

<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?

EDIT:

<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="#" 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

<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?

EDIT:

<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="#" 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

Share Improve this question edited Oct 22, 2021 at 7:04 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 4, 2009 at 19:25 krishnakrishna 111 gold badge1 silver badge2 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

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

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).

I just had this error and it was because I had a form element that was trying to submit to an action that was invalid.

Mine was and that was not a valid action.

If you are still having this error you should verify syntax as well as that your form is submitting to a valid method.

This error indicates bad html syntax or invalid source.

本文标签: onclickObject expected error message in JavascriptStack Overflow