Checking the values of two form fields

G

Gawie Marais

hi all,

i have a form and would like to check two fields.
if field 1 containes the letter 'c' and the other field contains
'undefined', then an error should apprear ina box on the screen.

can anyone point me a piece of code ?


Thanx,


Gawie.
 
S

Shawn Milo

Gawie Marais said:
hi all,

i have a form and would like to check two fields.
if field 1 containes the letter 'c' and the other field contains
'undefined', then an error should apprear ina box on the screen.

can anyone point me a piece of code ?


Thanx,


Gawie.

Untested. You may have to tweak it a tiny bit.
That way, you'll learn something.

Shawn



<script type="text/javascript">


function checkForm(){

var allOkay = true;

if ((document.forms['formName'].txtFred.value == 'jack') &&
(document.forms['formName'].txtBarney.value == 'jill')){
alert('You shouldn't have done that...');
allOkay = false;
}

return allOkay;
}


</script>



In form:

<form id="formName" action="./test.html" method="post"
onsubmit="if(!checkForm(){){return false;}">


<input type="text" id="txtFred" name="txtFred" value="" />
<br/>
<input type="text" id="txtBarney" name="txtBarney" value="" />

</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top