Simon Simon - 5 months ago 98
Javascript Question

javascript runtime error function is undefined

I get this


0x800a1391 - javascript runtime error function is undefined


When I try and click the save button.

Here is my code:



<script src="~/Scripts/jquery/jquery-1.6.2.min.js">
function disableSaveBtns(){
document.getElementbyId("save").prop("disabled", true);
document.getElementbyId("saveClose").prop("disabled", true);
}
</script>

<div class="submit-btn row">
<div class="col-md-12">
<span class="btn-group tlbEdit">
<a href="#" id="save" class="btn btn-sm btn-default saveObject" onclick="disableSaveBtns()" title="save changes">Save</a>
<a href="#" id="saveClose" class="btn btn-sm btn-default saveObject closeObject" title="save changes and close ">Save &amp; Close</a>
<a href="@Url.Action("Details", new { id = Model.id })" class="btn btn-sm btn-default btnCancelEdit" title="Cancel Edit">Close</a>
</span>
<span class="btn-group tlbClose">
<a href="#" class="btn btn-sm btn-default openAll">Expand All</a>
<a href="#" class="btn btn-sm btn-default closeAll">Collapse All</a>
</span>
</div>
</div>





I've checked the function declaration and I'm fairly certain that there are no syntax errors but I could be wrong. Could someone tell me why I'm getting the above error?

Answer

You need a new <script></script> element to put your code in. That should fix your problem.

<script src="~/Scripts/jquery/jquery-1.6.2.min.js"></script>
<script>
function disableSaveBtns(){
        document.getElementbyId("save").prop("disabled", true);
        document.getElementbyId("saveClose").prop("disabled", true);
    }
</script>