javascript help please

Associate
Joined
6 Jun 2004
Posts
93
Location
London
Hi thanks for taking a look at this!
I am using the below javascript to validate 2 feilds. For some reason if Max salary is lower it gives the below error message, however it also gives the same error even if the MaxSalary is higher!

I'm totoally lost! don;'t know why its doing this!


if (document.t1forms.MiSalary.value == "" < document.t1forms.MxSalary.value == "")
{
alert("Maximum Salary should be higher then Minimum Salary");
t1forms.MxSalary.focus()
valid = false;
}

thanks for all your help!
 
Tush said:
Hi thanks for taking a look at this!
I am using the below javascript to validate 2 feilds. For some reason if Max salary is lower it gives the below error message, however it also gives the same error even if the MaxSalary is higher!

I'm totoally lost! don;'t know why its doing this!

Code:
if (document.t1forms.MiSalary.value  < document.t1forms.MxSalary.value )
	{
		alert("Maximum Salary should be higher then Minimum Salary");
		t1forms.MxSalary.focus()
		valid = false;
	}
thanks for all your help!

i should have said i have ammended your code. sorry :p
 
Last edited by a moderator:
Guys can someone...

Advice me on this please, i don't really know why its not working!

I have a 2 feilds in my form Minimum pay and maximum pay I want to use Javascirpt to validate that maximum Pay is not less then Minimum Pay. I've used the above code but its not letting me validate the feilds!

Any suggestions would greatly be appreciated! thanks for all you time in advance!
 
If you look at the difference between Freak_boy's code and yours you will notice a subtle difference.

your If statement did not make any sense at all. you were not comparing the two values.

The JavaScript interperator would be erroring on
if (document.t1forms.MiSalary.value == "" < document.t1forms.MxSalary.value == "")

because it is not correct syntax.

change this to
if (document.t1forms.MiSalary.value < document.t1forms.MxSalary.value )
as seen in Freak_boy's post and you should see it working.
 
Hi Wiggis,
Thank you so much for you help, i tried it and at first it didn't work for an odd reason! But when i swapped it this way if did!

if (document.t1forms.MxSalary.value < document.t1forms.MiSalary.value)

I think we got the logical opterator mixed up it should have been like this > with the previous statement!

On another note how do i validate check boxes, i am totally lost here as all the examples i've seen only demonstrates check box validation on their own not as if it was part of the whole form and each bit being validated one by one whether its a feild or check box! hope this makes sense!

Any suggestions on this is much appreciated!

thanks
 
Tush said:
Hi Wiggis,
Thank you so much for you help, i tried it and at first it didn't work for an odd reason! But when i swapped it this way if did!

if (document.t1forms.MxSalary.value < document.t1forms.MiSalary.value)

I think we got the logical opterator mixed up it should have been like this > with the previous statement!

On another note how do i validate check boxes, i am totally lost here as all the examples i've seen only demonstrates check box validation on their own not as if it was part of the whole form and each bit being validated one by one whether its a feild or check box! hope this makes sense!

Any suggestions on this is much appreciated!

thanks

i should have said i have ammended your code. sorry :p

as for your second question nop it doesnt make sense to me :confused: do you mean something like if one checkbox is checked, you have to check anothr one too or what?
 
Back
Top Bottom