Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If textbox.value is a number or Text and run a function

Status
Not open for further replies.

Joelo

MIS
Sep 27, 2003
61
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);
}
}
}

 
<script>
var a='textString';
a = parseInt(a);
if (a!='NaN') {alert('text');} else {alert('number');}
</script>
 
Here's your answer, Joelo :)

var a='0'; // an integer
if (!isNaN(parseInt(a))) {alert(a+' is a number!');}

 
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 this function mim_MaxCheck() to run


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);
}
}
}
 
Yes, I'm happy to say that is exactly what it does :)

Assuming <input name=&quot;textbox0&quot;>, here it is pasted into your scenario:

Code:
var a=document.getElementsByName('textbox0')[0].value;
if (!isNaN(parseInt(a))) {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); 
} 
} 
}

Do I win a star? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top