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

form validation

Status
Not open for further replies.

abieyuwae

Programmer
Joined
Oct 12, 2000
Messages
1
Location
US
Hi,
I have two
fields. I'm trying to do a form validation, whereby, if a state is
selected, then you can't enter value for the province, but a province and
state can't both be empty. I tried this javascript function, but i'm still
having problems. Please can you help.

I tried this one first

function CheckState(){

if((state=="") &&(state_2=="")

alert("Please select either a state or type in the
Province.");

}

return false;

}

else return true;

}

Then this one

function checkInput() {

if ((state_name == "--None--")&&(state_2 =="")

alert("Please enter a value!");

}

return false;

}

else return true;

}

But nothing happend.

Below is the select and text box i'm trying to validate.Thanks
<SELECT name=&quot;payee_state&quot;>
<OPTION value=&quot;&quot; SELECTED>--None--
<CFOUTPUT query=&quot;getstates&quot;>
<OPTION value=&quot;#state_name#&quot; <CFIF
state_name IS GetPayees.state>
SELECTED</cfif>>#state_name#

</CFOUTPUT>
</SELECT>
&nbsp;or Type&nbsp;
<INPUT type=&quot;Text&quot; NAME=&quot;State_2&quot; size=&quot;18&quot; maxlength=&quot;60&quot; >


 
This should work. There has got to be a dozen different ways to do this but I typically use this method and it has never let me down:

<script language=&quot;JavaScript&quot;>
function Check()
{
var text1 = Test.payee_state.value
var text2 = Test.State_2.value
if ((text1.length < 1) && (text2.length < 1))
{
alert(&quot;Please select either a state or type in the Province.&quot;)
return false
}
return true
}
</script>

<form name=&quot;Test&quot; onSubmit=&quot;return Check()&quot;>
<SELECT name=&quot;payee_state&quot;>
<OPTION value=&quot;&quot; SELECTED>--None--</option>
<CFOUTPUT query=&quot;getstates&quot;>
<OPTION value=&quot;#state_name#&quot; <CFIF state_name IS GetPayees.state> SELECTED</cfif>>#state_name#</option>
</CFOUTPUT>
</select>
<INPUT type=&quot;Text&quot; NAME=&quot;State_2&quot; size=&quot;18&quot; maxlength=&quot;60&quot; >
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</form> [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top