mcrmg
asked on
call function
Hi,
this is my code
I am checking to see if user entered numeric value. Is there a way to call another function at the same time? such as
Thanks
this is my code
<asp:TextBox id="SqFtX" runat="server" Width="40px" onkeypress="return isNumber(event,$('#SqFtX').val())"></asp:TextBox>
I am checking to see if user entered numeric value. Is there a way to call another function at the same time? such as
<asp:TextBox id="SqFtX" runat="server" Width="40px" onkeypress="return isNumber(event,$('#SqFtX').val()); MyFunction();"></asp:TextBox>
Thanks
Basically, no. What you're actually calling is an event handler. An event can have only one event handler assigned to it. It would be possible to call a function from within the event handler. It's also possible to switch on some variable within the event handler so you can optionally run additional functions.
It is the "return" statement that is stopping the second function call.
Depending on what you want, any of the following should work
isNumber(event,$('#SqFtX') .val()); MyFunction(); return;
var retval = isNumber(event,$('#SqFtX') .val()); MyFunction(); return retval;
var retval = isNumber(event,$('#SqFtX') .val()); if (retval) { MyFunction(); } return retval;
Depending on what you want, any of the following should work
isNumber(event,$('#SqFtX')
var retval = isNumber(event,$('#SqFtX')
var retval = isNumber(event,$('#SqFtX')
ASKER
I think this should work
var retval = isNumber(event,$('#SqFtX') .val()); if (retval) { MyFunction(); } return retval;
When the value is numeric, it will call MyFunction. But for some reason, it is not. Am I missing something? thanks
var retval = isNumber(event,$('#SqFtX')
When the value is numeric, it will call MyFunction. But for some reason, it is not. Am I missing something? thanks
<td><asp:TextBox id="SqFt" runat="server" Width="80px" onkeypress="var retval = isNumber(event,$('#SqFtX').val()); if (retval) { MyFunction(); } return retval;"></asp:TextBox>
protected void MyFunction(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("HERE");
}
ASKER
Is there a way to call to a code behind function? This is my code, it looks like it posts back, but not getting to the function. I would like to see if there is a way to verify if the entry is numeric then call to a function. thanks
<asp:TextBox id="SqFt" runat="server" Width="80px" AutoPostBack="True" onkeypress="return isNumber(event,$('#SqFt').val())" Onclick ="MyFunction"></asp:TextBox>
It is different depending on whether MyFunction is in the javascript or in your code-behind. Sorry, I thought it was a javascript function you wanted to call.
When do you want the code-behind to execute? While the user is still typing in the text box (i.e. triggered by keypress event) or after they have finished typing?
When do you want the code-behind to execute? While the user is still typing in the text box (i.e. triggered by keypress event) or after they have finished typing?
ASKER
if it is possible, I would like to "block" user from entering non-numeric value (during or after validation is okay), then once they leave the field, a code behind function will be called. That function is basic grabbing the value that user just entered and do some calculations. thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.