Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-12-2010, 11:45 AM   PM User | #16
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
According to your latest code, you don't even validate for humidity & rainfall. All I can see is a validation for "temperature_max" and "temperature_max", which appear to work.

So?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 04-12-2010, 11:56 AM   PM User | #17
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Apart from is_leaf_fresh = -1;
for (i=0;i < thisform.is_leaf_fresh.length; i++)
which is bound to give trouble in some browsers. Use this instead:-

Code:
ilf = false;	 
for (i=0;i < thisform.is_leaf_fresh.length;  i++)   {
if (thisform.is_leaf_fresh[i].checked == true) {
ilf = true;
}
if (!ilf) {
alert("You must select an option for Fresh Leaf!");
return false;
}
You have

var numericExpression = /^[0-9]+$/;
if(temp_max.match(numericExpression) && (temp_max>=0 && temp_max<=50)){
return true;

which does exactly that, returns true and submits the form. As "true" is the default it is strictly speaking never necessary to have return true in a form validation. If you do, it should occur only once - right at the end.

Suggest you use something like this:-

Code:
var temp_max = document.getElementById("temperature_max").value;  // allows decimal values
// OR var temp_max = parseInt(document.getElementById("temperature_max",10).value); // if only whole numbers are allowed
if ((isNaN(temp_max)) || (!temp_max) || (temp_max <0) || (temp_max >50)) {
alert("Max Temperature value should be Numeric & between 0 to 50");
document.getElementById("temperature_max").value = "";  // clear the field
myfield = document.getElementById("temperature_max");    // note myfield must be a global variable
setTimeout('myfield.focus();myfield.select();' , 10);  // refocus on the field - overcome bug in Firefox
return false;
}
There seems to be no validation at all for humidity and rainfall.


Why are you not using Firebug as suggested?

Last edited by Philip M; 04-12-2010 at 12:19 PM..
Philip M is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:53 PM.


Advertisement
Log in to turn off these ads.