Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text field and alert not quite working

Status
Not open for further replies.

salamis

Programmer
Nov 1, 2001
3
CA
I still have a problem. What I need is if neither box is selected, I get a alert, and if both are selected I get a alert.
(only one of the two can be selected)
The problem occurs in the 2rd part with the !, if only one is selected, I still get the alert, but I am using &&

Any suggestions?

if ((frm.rePaymentPeriod.value == "") && (frm.monthlyCost.value == ""))
{
alert("You must choose either the montly \r"+
"cost or the repayment period field.");
frm.monthlyCost.focus();
frm.monthlyCost.select();
return false;
}

if (((parseInt (frm.rePaymentPeriod.value) !== "") && (parseInt (frm.monthlyCost.value) !== "")))
{
alert("You have selected both the montly \r"+
"cost and the repayment period fields.\r"+
"Please select only one.")
frm.monthlyCost.focus();
frm.monthlyCost.select();
return false;
}
return true;
}
 
I noticed that you're comparing an integer to an empty string. Not sure how JavaScript treats this but you might do something like this.
Code:
parseInt(frm.rePaymentPeriod.value) != 0
ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top