Click to See Complete Forum and Search --> : Checking two fields with an onblur


TomGuy
01-12-2004, 11:01 AM
Hi,

I'm new to the world of javascript and I'm having a bit of a problem with my onblur event. I have two fields in a form (a text box and a hidden object). The hidden object's value contains the minimum value allowed to be entered into the text box. Therefore on the textbox "OnBlur" event I want to make sure that the number they entered into the textbox is greater than the minimum value contained in the hidden object...hopefully this will make sense after you look at my code:

**JavaScript**
function CheckQty(DesiredQty, MinQty)
{
//The following alert box is used for testing - the DesiredQty
comes back with whatever was entered into the textbox
however the MinQty comes back as "undefined"
alert(DesiredQty.value + MinQty.value);

if (DesiredQty.value < MinQty.value)
{
alert('You have entered a number below the minimum Quantity. Please adjust your desired quantity.');
return 0;
}
}

**HTML**
<FORM NAME="dspProducts">
<INPUT TYPE="hidden" NAME="hidMinQty" value="5">
<INPUT TYPE="TEXT" NAME="makeQty"
onblur="CheckQty(document.dspProducts.makeQty, document.dspProducts.hidMinQty)">


It may be that this event doesn't support calling two fields...Not sure....If that's the case can anyone think of a different way to handle this?

Thanks!

Tom

TheBearMay
01-12-2004, 11:15 AM
Actually works fine for me as long as I convert the fields to integer. Otherwise you're comparing text strings.

function CheckQty(DesiredQty, MinQty){
//The following alert box is used for testing - the DesiredQty
// comes back with whatever was entered into the textbox
// however the MinQty comes back as "undefined"
alert(DesiredQty.value + MinQty.value);

if (parseInt(DesiredQty.value) < parseInt(MinQty.value))
{
alert('You have entered a number below the minimum Quantity. Please adjust your desired quantity.');
return 0;
}
}

TomGuy
01-12-2004, 11:33 AM
Ok, well let me reveal a bit more then....I didn't mention this in my original post because I didn't think it should make a difference, however perhaps it does....The value of the hidden object is being filled with a variable resolved by a cold fusion server, i.e.:
<INPUT TYPE="hidden" NAME="hidMinQty" value="#curntMinQty#">
I know that is is resolving the variable because if I change it from a hidden object to a text box, the number 5 appears in text box. I would think that this shouldn't make a difference but maybe it does...any thoughts?

TomGuy
01-12-2004, 02:59 PM
Hi,

I figured it out. It was because the name of the hidden object was the same as another hidden object on the form. :rolleyes:

Thanks,

Tom