Click to See Complete Forum and Search --> : If textbox is a number or Text and run a function
joelo
11-30-2003, 12:02 AM
Please I have a Dynamic form and I'm in need of some javascript code that will check textboxes display with loop if their value content is text or number and run a function.
i.e
If textbox0.value is a text then
do nothing
else if textbox0.value is a number then
run this function mim_MaxCheck()
function min_maxCheck(){
for(i=1; i< <%= Ext_Record_Count%>+1; i++) {
if (document.getElementById('PRE_idLEFTPRESSURE_'+i).value < document.getElementById('PRE_idSETPOINTPRESSURE_'+i).value * 0.95 || document.getElementById('PRE_idLEFTPRESSURE_'+i).value > document.getElementById('PRE_idSETPOINTPRESSURE_'+i).value * 1.05){
alert('ERROR!!!...LEFT PRESSURE out of Range');
document.getElementById('PRE_idLEFTPRESSURE_'+i).focus()
return (false);
}
}
}
Pittimann
11-30-2003, 01:48 AM
Hi!
Three suggestions:
1. block input other than figures - check out that ->
http://javascript.internet.com/forms/block-press-script.html#source
2. check the input for values other than figures - check out that - > http://javascript.internet.com/forms/commas.html#source
Just examples for you, but from both scripts you can grab the code you need and integrate it to your script.
3. if the possible numeric values in your form are not too many why not use a dropdown with all values predefined. That is the safest way (if you don't use server side programming) to prevent the user from entering and submitting invalid stuff.
Cheers - Pit
joelo
11-30-2003, 03:44 AM
Please Does any anyone know how I can get it accomplished
Please help me out
joelo
11-30-2003, 02:28 PM
could anybody help me
Does the following example help you
<script>
function chkme(){
data=document.f1.t1.value
if(isNaN(data)==true){
alert("This is not a number")
}
else{
alert("This is a number")
}
}
</script>
<form name="f1">
<input type="text" name="t1"><BR>
<input type="button" value="Click Me" onclick="chkme()">
</form>
joelo
11-30-2003, 03:06 PM
This is what I am trying to do:
If textbox0.value == text then
do nothing (accept the Text in the TEXTBOX)
else if textbox0.value isNaN number then
trigger function mim_MaxCheck() to run and validate the number value
All you need to add to your function then is
data=document.FormName.ElementName.value
if(isNaN(data)==true){
mim_MaxCheck()
return
}
where
document.FormName.ElementName.value
is the textbox value
Asiralia
12-02-2003, 08:06 AM
Hi,
I just tried your suggestion in my code and I seem to have made a mistake.
<script language="JavaScript">
function NumericCheck(){
data=document.f1.agent.value
if(isNaN(data)==true){
alert("You have entered a character in a numeric field")
}
}
</script>
<div align="right"><b>Agent Number</b></div>
</td>
<td>
<input type="text" name="agent" align="right" size="8" maxlength="10" value=" " tabindex="10" class="textNumber" class="textNumber" onclick="NumericCheck()">
But it is not working...it is going on to the next screen (saying that the agent isnt found... any ideas?
Please try the following
<script language="JavaScript">
function NumericCheck(){
data=document.f1.agent.value
if(isNaN(data)==true){
alert("You have entered a character in a numeric field")
}
}
</script>
<div align="right"><b>Agent Number</b></div>
</td>
<td> <form name="f1">
<input type="text" name="agent" align="right" size="8" maxlength="10" value=" " tabindex="10" class="textNumber" class="textNumber" onblur="NumericCheck()">
</form>
Asiralia
12-02-2003, 11:12 AM
Thank you.