is this possible

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

i have a webform with a textbox that has a client-side onChange event.
what's the best way to validate this?

for example,
the textbox value needs to be a number or else don't run the client-side
onChange event. Is it possible to use the compare validator to accomplish
this?

p.s. i asked this a couple of days ago and felt like i wasn't very clear
with what i was asking (i apologize). I hope this is a little better.

thanks,
rodchar
 
mmm
i think you can use a validator control, link the validator to your textbox
and when validation is successful run your code
 
but it's a client-side onChange event. i don't see how i can use the
validator on the client-side so that if it's not a number not to run the
client-side function.

sorry if i'm not seeing this so easily.
 
If all that you need from the textbox onchange event is to do processing on
the client then you can do that using Javascript like this:
<script language="javascript">
function VerifyNumber()
{

var input = window.event.srcElement;
//this is a regular expression to verify any real number
if (!/^(\+|-)?\d+(\.\d+)?$/.test(input.value) )
{
alert("invalid entry");
input.value=""; //blank out the entry
}
else
{

//do something else
}

}
</script>

and then in the web form you would write something like this:
<asp:TextBox ID="textBox1" Runat=server oncheck="VerifyNumber();"
 
what does this line do?
"var input = window.event.srcElement;"


Phillip Williams said:
If all that you need from the textbox onchange event is to do processing on
the client then you can do that using Javascript like this:
<script language="javascript">
function VerifyNumber()
{

var input = window.event.srcElement;
//this is a regular expression to verify any real number
if (!/^(\+|-)?\d+(\.\d+)?$/.test(input.value) )
{
alert("invalid entry");
input.value=""; //blank out the entry
}
else
{

//do something else
}

}
</script>

and then in the web form you would write something like this:
<asp:TextBox ID="textBox1" Runat=server oncheck="VerifyNumber();"
</asp:TextBox>
--
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
-----
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


rodchar said:
but it's a client-side onChange event. i don't see how i can use the
validator on the client-side so that if it's not a number not to run the
client-side function.

sorry if i'm not seeing this so easily.
 
That line gets a reference to the object that triggered the event (in this
case the <input> object that triggered the onCheck event).

rodchar said:
what does this line do?
"var input = window.event.srcElement;"


Phillip Williams said:
If all that you need from the textbox onchange event is to do processing on
the client then you can do that using Javascript like this:
<script language="javascript">
function VerifyNumber()
{

var input = window.event.srcElement;
//this is a regular expression to verify any real number
if (!/^(\+|-)?\d+(\.\d+)?$/.test(input.value) )
{
alert("invalid entry");
input.value=""; //blank out the entry
}
else
{

//do something else
}

}
</script>

and then in the web form you would write something like this:
<asp:TextBox ID="textBox1" Runat=server oncheck="VerifyNumber();"
</asp:TextBox>
--
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
-----
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


rodchar said:
but it's a client-side onChange event. i don't see how i can use the
validator on the client-side so that if it's not a number not to run the
client-side function.

sorry if i'm not seeing this so easily.

:

mmm
i think you can use a validator control, link the validator to your textbox
and when validation is successful run your code

"rodchar" <[email protected]> escribió en el mensaje
hey all,

i have a webform with a textbox that has a client-side onChange event.
what's the best way to validate this?

for example,
the textbox value needs to be a number or else don't run the client-side
onChange event. Is it possible to use the compare validator to accomplish
this?

p.s. i asked this a couple of days ago and felt like i wasn't very clear
with what i was asking (i apologize). I hope this is a little better.

thanks,
rodchar
 
thanks for the help.

Phillip Williams said:
That line gets a reference to the object that triggered the event (in this
case the <input> object that triggered the onCheck event).

rodchar said:
what does this line do?
"var input = window.event.srcElement;"


Phillip Williams said:
If all that you need from the textbox onchange event is to do processing on
the client then you can do that using Javascript like this:
<script language="javascript">
function VerifyNumber()
{

var input = window.event.srcElement;
//this is a regular expression to verify any real number
if (!/^(\+|-)?\d+(\.\d+)?$/.test(input.value) )
{
alert("invalid entry");
input.value=""; //blank out the entry
}
else
{

//do something else
}

}
</script>

and then in the web form you would write something like this:
<asp:TextBox ID="textBox1" Runat=server oncheck="VerifyNumber();"
</asp:TextBox>
--
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
-----
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

but it's a client-side onChange event. i don't see how i can use the
validator on the client-side so that if it's not a number not to run the
client-side function.

sorry if i'm not seeing this so easily.

:

mmm
i think you can use a validator control, link the validator to your textbox
and when validation is successful run your code

"rodchar" <[email protected]> escribió en el mensaje
hey all,

i have a webform with a textbox that has a client-side onChange event.
what's the best way to validate this?

for example,
the textbox value needs to be a number or else don't run the client-side
onChange event. Is it possible to use the compare validator to accomplish
this?

p.s. i asked this a couple of days ago and felt like i wasn't very clear
with what i was asking (i apologize). I hope this is a little better.

thanks,
rodchar
 
Back
Top