Click to See Complete Forum and Search --> : Page Validation


gowans007
11-08-2004, 06:00 AM
Ok guys I am writing a simple verification code for uni where you enter your borrowing and what you want to borrow and a purpose.

The validation to check details are entered work fine till I get to purpose.

Basically I have to forms:
one named "purpose" which is a drop down of common options including an other option.
and "purpose_other" for when the other option is selected.

I want the validation to check when other is selected (other is default value on dropdown) that a value must be entered into the purpose_other text box (Blank and a space must not be accepted).

This is letting me down at the moment can you guys help and tell me whats worng???

Thanks for your help guys

CODE FOLLOWS


<SCRIPT LANGIAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

<!-- Hide script from older browsers

function isCurrentod(passedVal){


for (i=0; i<passedVal.length; i++){

if (passedVal.charAt(i) < "0"){
return false
}

if (passedVal.charAt(i) > "9"){
return false

}

}


return true

}


function validCurrentod(inCurrentod){
if (inCurrentod == "") {
return false
}
if (isCurrentod(inCurrentod)) {
return true

}

return false
}



function isRequiredod(passedVal){


for (i=0; i<passedVal.length; i++){

if (passedVal.charAt(i) < "0"){
return false
}

if (passedVal.charAt(i) > "9"){
return false

}

}


return true

}


function validRequiredod(inRequiredod){
if (inRequiredod == "") {
return false
}
if (isRequiredod(inRequiredod)) {
return true

}

return false
}

function validPurpose(inPurpose){
if (inPurpose == "Other") {

if (odForm.purpose_other.value == "") {

return false

}

if (odForm.purpose_other.value == " ") {

return false

}

}

return true
}


function submitIt(odForm){


if (!validCurrentod(odForm.cur_od.value)){
alert ("You must enter a Current Overdraft")

odForm.cur_od.focus()
odForm.cur_od.select()

return false

}

if (!validRequiredod(odForm.req_od.value)){
alert ("You must enter a Required Overdraft")

odForm.req_od.focus()
odForm.req_od.select()

return false

}

if (!validPurpose(odForm.purpose.value)){
alert ("You must enter a Purpose")

odForm.purpose.focus()
odForm.purpose.select()

return false

}

return true
}


// End hiding script -->
</SCRIPT>

Charles
11-08-2004, 06:06 AM
It's hard to poast a solution without testing it first, and while I'm typing with two hands for the first time in three months, I remain too lazy to type out something like your form just so that I can play with it. Please get your page to pass the Validator (http://validator.w3.org/) as HTML 4.01 Strict (http://www.w3.org/TR/html401/) and then post a link.

gowans007
11-08-2004, 08:21 AM
Page example:

you can copy the following basic code I've just knocked up into a text file and call it .htm.

---------------------------------------------------------------
---------------------------------------------------------------

<html>
<head>

<SCRIPT LANGIAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

<!-- Hide script from older browsers

function isCurrentod(passedVal){


for (i=0; i<passedVal.length; i++){

if (passedVal.charAt(i) < "0"){
return false
}

if (passedVal.charAt(i) > "9"){
return false

}

}


return true

}


function validCurrentod(inCurrentod){
if (inCurrentod == "") {
return false
}
if (isCurrentod(inCurrentod)) {
return true

}

return false
}



function isRequiredod(passedVal){


for (i=0; i<passedVal.length; i++){

if (passedVal.charAt(i) < "0"){
return false
}

if (passedVal.charAt(i) > "9"){
return false

}

}


return true

}


function validRequiredod(inRequiredod){
if (inRequiredod == "") {
return false
}
if (isRequiredod(inRequiredod)) {
return true

}

return false
}

function validPurpose(inPurpose){
if (inPurpose == "Other") {

if (odForm.purpose_other.value == "") {

return false

}

if (odForm.purpose_other.value == " ") {

return false

}

}

return true
}


function submitIt(odForm){


if (!validCurrentod(odForm.cur_od.value)){
alert ("You must enter a Current Overdraft")

odForm.cur_od.focus()
odForm.cur_od.select()

return false

}

if (!validRequiredod(odForm.req_od.value)){
alert ("You must enter a Required Overdraft")

odForm.req_od.focus()
odForm.req_od.select()

return false

}

if (!validPurpose(odForm.purpose.value)){
alert ("You must enter a Purpose")

odForm.purpose.focus()
odForm.purpose.select()

return false

}

return true
}


// End hiding script -->
</SCRIPT>

<body>

<form onSubmit="return submitIt(this)" action="next.htm">

Current OD:
<br>
<input name="cur_od" type="text" class="BodyText" id="cur_od" size="4" maxlength="4">
<br>
<br>
Required OD:
<br>
<input name="req_od" type="text" class="BodyText" id="cur_od" size="4" maxlength="4">
<br>
<br>
Purpose:
<br>
<select name="purpose" class="BodyText" id="purpose">
<option value="General Living Costs">General Living Costs</option>
<option value="Rent">Rent</option>
<option value="Course Fees">Course Fees</option>
<option value="Other" selected>Other</option>
</select>
<br>
<br>
Purpose Other:
<br>
<input name="purpose_other" type="text" class="BodyText" id="purpose_other" size="34">
<br>
<br>

<input name="Submit" type="submit" class="BodyText" value="Save &amp; Continue">

</form>

</body>
</html>

gowans007
11-09-2004, 11:08 AM
any luck guys???????????????????????????????