How to make call to JavaScript function work?

Kathleen Lum Kathleen Lum asked Dec 10, 2015
Active Dec 11 · Viewed 1091 times
<p>I have defined a function and would like to make it work, but it doesn't. What do I do wrong?</p><p>The function duh() is defined in a ScriptBlock. The form contains a single text&nbsp;field. If I do onchange="alert('Duh!');" on the field, this works. If I do onchange="duh();" the function doesn't seem to be called, I just move to the next field on my form (which I stripped to create a minimal example).&nbsp;</p><p>&lt;AddForm ClientName="Register"&gt;</p><p>&lt;ScriptBlock BlockType="HeadScript" RegisterOnce="True" ScriptId="CalculationScript"&gt;</p><p> &lt;script language="javascript"&gt;</p><p> function duh() { alert("Duh!"); }</p><p>&lt;/script&gt;</p><p>&lt;/ScriptBlock&gt;</p><p>&lt;div class="..."&gt;</p><p>&lt;div class="..."&gt;</p><p>&lt;div&gt; &lt;span&gt;&lt;strong&gt;Your</p><p> Name&lt;/strong&gt;&lt;/span&gt;</p><p> &lt;TextBox Id="Name" CssClass="form-control required" DataField="Name" DataType="string" onchange="duh()"&gt;</p><p> &lt;/TextBox&gt;</p><p> &lt;/div&gt;</p><p>&lt;/div&gt;</p><p>&lt;/div&gt;</p><p>&lt;/AddForm&gt;</p>

2 Answers

Loading answers...