Javascript Validation
I want to validate a textbox, currently im using this:
<script type="text/javascript">
function validate_form (){
var Motor_Frame = document.getElementById('Motor_Frame');
if(Motor_Frame.value == ""){
alert("Please fill in Motor Frame. If no motor please fill in with N/M")
document.forms[0].Motor_Frame.focus();
return false;}
return true;
}
</script>
but i want it to check a few values the textbox is allowed:
1. if its blank display an error
2. if it doesnt equal a/p, n/r, n/q or a value between 1 and 500 then display an error.
morrisproject
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
yes thats true but it could also be a value between 1 and 500 as well....
morrisproject
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
i now have this:
<script type="text/javascript">
function validate_form (){
var Motor_Frame = document.getElementById('Motor_Frame');
if( (Motor_Frame.value != "a/p" || Motor_Frame.value != "n/r" || Motor_Frame.value != "n/q") || (parseInt(Motor_Frame.value) < 0 && parseInt(Motor_Frame.value) > 500)){
alert("Please fill in Motor Frame")
document.forms[0].Motor_Frame.focus();
return false;}
return true;
}
</script>
but my error comes up everytime, even if i eneter a number, n/q, n/r or a/p???
morrisproject
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
i can now enter anything or leave it blank and it will still save......
morrisproject
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0