is this possible

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
 
R

Rick

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

Guest

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

Guest

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();"
 
G

Guest

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

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top