pikemsu28 Posted April 24, 2007 Share Posted April 24, 2007 i'm trying to validate a form that converts pounds to kilos and kilos to pounds. but i want to put a stop that if you are converting pounds to kilos, the user cannot enter more than 550 pounds, and if the user is converting kilos to pounds, they cant enter more than 250 kilos. i'm using two radio buttons to select if they are entering in pounds or kilos. this is what i have so far: <script type="text/javascript"> function checkWeight() { var cweight; with(window.document.form1) { cweight = weight; } if(trim(cweight.value) == '') { alert("Please enter patient's Weight."); cweight.focus(); return false; } else if(isNaN(trim(cweight.value))) { alert("Please enter only Numeric Values for Weight."); cweight.focus(); return false; } else { cweight.value = trim(cweight.value); return true; } } </script> <form id="form1" name="form1" method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <input id="conv" name="conv" type="radio" value="kg" /><label for="conv">Kilograms</label> <input id="conv" name="conv" type="radio" value="lbs" /><label for="conv">Pounds</label> <label for="weight">Weight of Patient:</label><input id="weight" name="weight" type="text" maxlength="6" class="box" value="<?php if(isset($_POST['weight'])){echo $_POST['weight'];}?>" /> <?php if(!isset($_POST['override'])){ echo $_POST['conv'];}?> <input id="convert" name="convert" type="submit" class="button" value="Convert Weight" onclick="return checkWeight()" /> if conv == 'lbs' then the value needs to be less than 551. if conv == 'kg' the value needs to be less than 251. i'm not sure on how to go about this. i've done some look up andi know that the radio buttons need to go thru a for loop to see which one is check, but as for that, i'm not sure how to implement that into my code. if someone could help me out, i would really appreciate it! thanks, jason Quote Link to comment Share on other sites More sharing options...
fenway Posted April 24, 2007 Share Posted April 24, 2007 What's wrong with an if() statement? Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted April 26, 2007 Author Share Posted April 26, 2007 i tried it like this but it didnt work. i have no experience with javascript so i dont know where to go from here. function checkWeight() { var cweight, cconv; with(window.document.form1) { cweight = weight; cconv = conv; } if(trim(cweight.value) == '') { alert("Please enter patient's Weight."); cweight.focus(); return false; } else if(isNaN(trim(cweight.value))) { alert("Please enter only Numeric Values for Weight."); cweight.focus(); return false; } else if(trim(cconv.value)=='kg') { if(trim(cweight.value)>250) { alert("Please verify Weight."); cweight.focus(); return false; } } else if(trim(cconv.value)=='lbs') { if(trim(cweight.value)>550) { alert("Please verify Weight."); cweight.focus(); return false; } } else { cweight.value = trim(cweight.value); cconv.value = trim(cconv.value); return true; } } Quote Link to comment Share on other sites More sharing options...
fenway Posted April 26, 2007 Share Posted April 26, 2007 It's hard to follow that logic, but make sure you're getting into that control path. Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted April 26, 2007 Author Share Posted April 26, 2007 do you have any suggestions? i'm grasping at straws because of my lack of javascript knowledge. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 26, 2007 Share Posted April 26, 2007 Lace your function with alert()s. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.