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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript If statement -- (this condition) or (that condition)

Status
Not open for further replies.

RottPaws

Programmer
Mar 1, 2002
478
US
I've got a checkbox and 2 text boxes on a form. If the checkbox is checked and something is entered into either text box, I want the checkbox to be unchecked.

I've got the following function that is called by the onblur event of both text boxes.
[tt]
function ClearCheck(){
alert("Got to ClearCheck function");
alert("Text1=" + document.GetCriteria.Text1.value);
alert("Text2=" + document.GetCriteria.Text2.value);
if (document.GetCriteria.Text1.value!=""){
alert("Clear Checkbox");
document.GetCriteria.Check1.checked=false;
}
}
[/tt]
It works when either textbox value is changed if there is a value in Text1. But I also need it to work if Text1 is blank and something is entered into Text2. I can't figure out or find example of the correct syntax for 'this condition or that condition' in the IF statement.

Can I do that in javascript, or do I need to separate IF statements? _________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
you were close!
Code:
function ClearCheck(){
    alert("Got to ClearCheck function");
    alert("Text1=" + document.GetCriteria.Text1.value);
    alert("Text2=" + document.GetCriteria.Text2.value);
    if (document.GetCriteria.Text1.value!=""
Code:
 || document.GetCriteria.Text2.value!=""
Code:
){
        alert("Clear Checkbox");
        document.GetCriteria.Check1.checked=false;
        }
    }

|| means 'or'
&& means 'and'

Good luck! -gerrygerry

Standard response to one of my posts:
"No where in your entire rantings did you come anywhere close to what can be considered a rational answer. We are all now dumber from having heard that. I award you no points and may God have mercy on your soul."
 
Not for sure if this will work

if (document.GetCriteria.Text1.value!="" || document.GetCriteria.Text2.value!=""){
alert("Clear Checkbox");
document.GetCriteria.Check1.checked=false;
}
 
Perfect! Thanks.

I actually had the word 'or' in the code, but it didn't like that . . . _________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top