Is is possible to do “in form” validation without the alert boxes? What I’d like to do is give the user a message above or below the offending input areas.
@steelersfan88Jul 10.2004 — #Along the lines of:[code=php]<script type="text/javascript">
function checkForm(frm) { var uName = frm.elements[0].value var age = frm.elements[1].value var ctry = frm.elements[2].value var ret = true if(uName.split(', ').length != 2) { document.getElementById('prob0').innerHTML = "Incorrect Name!" ret = false } if(isNaN(age) || age == 0) { document.getElementById('prob1').innerHTML = "Must be Numeric!" ret = false } if(ctry != "US") { document.getElementById('prob2').innerHTML = "US Born Only!" ret = false } return ret; }
</script>
<div id="form" style="float:left;text-align:center"> <form name="myForm" onsubmit="return checkForm(this)"> <div id="obj" style="height:30px;float:left;">Name (Last, First): <input type="text" name="uName"></div><BR><BR> <div id="obj" style="height:30px;float:left;">Age: <input type="text" name="uName"></div><BR><BR> <div id="obj" style="height:30px;float:left;">Country: <input type="text" name="uName"></div><BR><BR> <input type="submit"> </form> </div> <div id="spc" style="width:35px;float:left"> </div> <div id="checks" style="float:left"> <div id="prob0" style="color:red;font-weight:bold;height:30px;float:left;"> </div><BR><BR> <div id="prob1" style="color:red;font-weight:bold;height:30px;float:left;"> </div><BR><BR> <div id="prob2" style="color:red;font-weight:bold;height:30px;float:left;"> </div><BR><BR> </div>[/code]The CSS could be a lot better ... thats what happens in the early morning ?
@keithh0427authorJul 10.2004 — #Thanks for the quick reply. The problem though is that it needs to be above or below the input. I have very little room for flexibility because the form is on a side panel.
I've thought about displaying some "White" text below the input and then calling a routing to change it to "Red", just cannot figure out how to do it.
@steelersfan88Jul 10.2004 — #Noo, you'd rather change the visibility or display properties. You wouldn't want a user finding the text when they aren't supposed to. Also, the doctype you have is not complete.[code=php]<html> <head> <title>Untitled</title> <script type="text/javascript"> <!-- function checkForm(frm) { var toGo=true; if(!frm.info_name.value.length) { document.getElementById("val_name").style.visibility="visible"; toGo=false;
@keithh0427authorJul 11.2004 — #I apologize for late thank you to all who responded. Our doughter just provided us with our 4th grandson and I got a little busy. Thanks to everyone for helping me out on this.
@steelersfan88Jul 11.2004 — #[i]Originally posted by fredmv [/i]
[B]Global solution: <http://www.peterbailey.net/fValidate/>. [/B][/QUOTE]But that takes all the fun away from doing the work by one's self! 'Tis great for beginners to the language though.