PDA

View Full Version : Form conditional validation


westrey
04-13-2004, 07:19 AM
Need a script to validate as follows:-
if Matchtype = 'sun cup' then uLimit = 40 ]
if Matchtype = 'sat lge' then uLimit = 45 ]- Matchtype is a required field and must be an integer
if Matchtype = 'eve lge' then uLimit = 20 ]

Dateplayed is a required field and must not be greater than current - display format dd mmm yyyy

Matchstatus is a required field and
if Matchstatus = 'Completed' to display the following fields:-
Batfirst from drop down list must have a team selected
Batfirstpts required field from drop down list
"batted 1st and scored" literal string
firstscore required integer field in range 0 to 500 inclusive
firstwks required field from drop down list
" in " literal string
limit1 required numeric field in the range 0.1 to uLimit

Display all Matchstatus fields on 1 line run html for example

Same validation for Bat2nd, Bat2ndpts etc and display on 2nd line

Team selected from Batfirst drop down list must be different from team selected from Bat2nd Drop down list.


if Matchstatus = 'Cancelled Weather' then display both team drop down lists as above and concatenate the string
" match cancelled " to both lines do not display and disable validation specified for Matchstatus = 'Completed' apart from selecting both teams.

if Matchstatus = 'oppCancelled' then display both team drop down lists as above and concatenate the string
" cancelled (-2pts)" to line1 and " awarded game (+2pts) " to line 2 do not display and disable validation specified for Matchstatus = 'Completed' apart from selecting both teams.

if Matchstatus = 'Abandoned' then display both team drop down lists as above and concatenate the string
" match abandoned " to both lines do not display and disable validation specified for Matchstatus = 'Completed' apart from selecting both teams.

HTML code between tags below
[CODE]
<html>
<head><title>JavaScriptValidation</title></head>
<body bgcolor="#FFFFFF" text="#000000">


<FORM name="mainform" method="POST" action="mailto:gwreyno@hotmail.com?subject= Test Hidden Concatenation" onsubmit="return validate()&&ConcatIt();" enctype="text/plain">

<table border=0 align=center valign=top bordercolor="#111111" width='85%'>

<tr><td colspan=7>&nbsp;</td></tr>

<tr>

<td><select name="Matchtype">
<option value="Match Type">Select Match Type</option>
<option value="Sun Cup">Sunday Cup</option>
<option value="Sat Lge">Saturday League</option>
<option value="Eve Lge">Evening League</option>
</select>
</td>

<td colspan=1>
<select name="Dateplayed">
<option value="Select Match Date from list">Select Match Date from list</option>
<option value="25 April 2004">25 April 2004</option>
<option value="2 May 2004">2 May 2004</option>
<option value="16 May 2004">16 May 2004</option>
<option value="30 May 2004">30 May 2004</option>
<option value="6 June 2004">6 June 2004</option>
<option value="13 June 2004">13 June 2004</option>
<option value="27 June 2004">27 June 2004</option>
<option value="11 July 2004">11 July 2004</option>
<option value="25 July 2004">25 July 2004</option>
<option value="1 Aug 2004">1 Aug 2004</option>
</select>
</td>

<td colspan=6>
<select name="Matchstatus" id="Matchstatus" onChange="checkStatus(this.id, this.value);">
<option value="Select Match Status from list">Select Match Status from list</option>
<option value="Complete">Completed</option>
<option value="Cancelled weather">Cancelled - bad weather</option>
<option value="Oppcancelled">Oppostion (-2pts) cancelled .... 2pts to other team</option>
<option value="Abandoned">Abandoned - before 25 overs completed in 2nd innings - 1pt each</option>
</select>
</td>
</tr>

<tr><td colspan=7>&nbsp;</td></tr>

<Input name="hiddenresult" value=Hometeam + Awayteam type=hidden>

<tr>
<td colspan=7 NOWRAP>
<select name="Batfirst" id="Batfirst">
<option value="Select Team">Select Team 1</option>
<option value="Bedrock">Bedrock</option>
<option value="Calmx">Calmx</option>
<option value="Chippendale">Chippendale</option>
<option value="Corsthe">Corsthe</option>
<option value="Devx1">Devx1</option>
<option value="Trospan">Trospan</option>
<option value="Wasbat">Wasbat</option>
<option value="Westlife2">Westlife2</option>
</select>

<select name="Batfirstpts">
<option value="Select Pts">Select Pts</option>
<option value="(0pts)">(0pts)</option>
<option value="(1pt)">(1pt)</option>
<option value="(2pts)">(2pts)</option>
<option value="(-2pts)">(-2pts)</option>
</select>

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">
batted 1st &amp; scored </font><input type=text SIZE=2 name="firstscore">

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2"> for </font>
<select name="firstwkts">
<option value="Select Wkts">Select Wkts</option>
<option value="0 wkts">0 wkts</option>
<option value="1 wkts">1 wkt</option>
<option value="2 wkts">2 wkts</option>
<option value="3 wkts">3 wkts</option>
<option value="4 wkts">4 wkts</option>
<option value="5 wkts">5 wkts</option>
<option value="6 wkts">6 wkts</option>
<option value="7 wkts">7 wkts</option>
<option value="8 wkts">8 wkts</option>
<option value="9 wkts">9 wkts</option>
<option value="10 wkts">10 wkts</option>
</select>

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2"> in </font>

<input type=text SIZE=2 name="limit1">

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2"> overs </font>

</td>
</tr>

<tr><td colspan=7>&nbsp;</td></tr>

<tr>
<td colspan=7 NOWRAP>
<select name="Bat2nd">
<option value="Select Team">Select Team 2</option>
<option value="Bedrock">Bedrock</option>
<option value="Calmx">Calmx</option>
<option value="Chippendale">Chippendale</option>
<option value="Corsthe">Corsthe</option>
<option value="Devx1">Devx1</option>
<option value="Trospan">Trospan</option>
<option value="Wasbat">Wasbat</option>
<option value="Westlife2">Westlife2</option>
</select>

<select name="Bat2ndpts">
<option value="Select Pts">Select Pts</option>
<option value="(0pts)">(0pts)</option>
<option value="(1pt)">(1pt)</option>
<option value="(2pts)">(2pts)</option>
<option value="(-2pts)">(-2pts)</option>
</select>

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">
batted 2nd &amp; scored </font><input type=text SIZE=2 name="secondscore">

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2"> for </font>
<select name="secondwkts">
<option value="Select Wkts">Select Wkts</option>
<option value="0 wkts">0 wkts</option>
<option value="1 wkts">1 wkt</option>
<option value="2 wkts">2 wkts</option>
<option value="3 wkts">3 wkts</option>
<option value="4 wkts">4 wkts</option>
<option value="5 wkts">5 wkts</option>
<option value="6 wkts">6 wkts</option>
<option value="7 wkts">7 wkts</option>
<option value="8 wkts">8 wkts</option>
<option value="9 wkts">9 wkts</option>
<option value="10 wkts">10 wkts</option>
</select>

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">
in </font>

<input type=text SIZE=2 name="limit2">

<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2"> overs </font>

</td>
</tr>

<tr><td colspan=7>&nbsp;</td></tr>

<tr>
<td colspan=7 align=left><font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">Match Report and Notable Performances:-</font>
<textarea name="Report" cols="100" rows="15"></textarea>
</td>
</tr>

<tr><td></td><td align=left>
<input type="submit" value="Submit Result">

<input type="reset" value="Start again">
</td></tr>

<TR><TD colspan=7>
<font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">
<p align=center><br><br>Fill in <b>ALL</b> relevant fields above then click <B>Submit Result</B> button.&nbsp; &nbsp; &nbsp; &nbsp; <br></p>
</TD></TR>

</form>

</table>

</body>
</html>


:confused:

Willy Duitt
04-14-2004, 02:04 AM
How about posting a link to what you have?
Your queston(s) does not make much sense and it has been sitting here unaswered for longer than normal. I would like to help you if I only knew what it was you are asking.

What I could make out in the overwhelming script above is that you need a way to find "sun cup" within Matchtype.....

eg:
if(Matchtype.indexOf('sun cup'){
alert('do this or that')
}

.....Willy

westrey
04-14-2004, 05:59 AM
Originally posted by Willy Duitt
How about posting a link to what you have?
Your queston(s) does not make much sense and it has been sitting here unaswered for longer than normal. I would like to help you if I only knew what it was you are asking.

What I could make out in the overwhelming script above is that you need a way to find "sun cup" within Matchtype.....

eg:
if(Matchtype.indexOf('sun cup'){
alert('do this or that')
}

.....Willy

Willy,

I only want to perform the checks in the function validate() if matchstatus='Complete'
otherwise I need to concatenate a literal string to the teams selected after ensuring the fields required for matchstatus='Complete' are not displayed. Please run the javascript shown between
tags below with the html I posted when I opened up this thread for more info.




function ConcatIt()
{
{
document.getElementById('hiddenresult').value = document.getElementById('Batfirst').value + " "
document.getElementById('hiddenresult').value += document.getElementById('Batfirstpts').value + " batted 1st and scored "
document.getElementById('hiddenresult').value += document.getElementById('firstscore').value + " for "
document.getElementById('hiddenresult').value += document.getElementById('firstwkts').value + " in "
document.getElementById('hiddenresult').value += document.getElementById('limit1').value + " overs. In reply "

document.getElementById('hiddenresult').value += document.getElementById('Bat2nd').value + " "
document.getElementById('hiddenresult').value += document.getElementById('Bat2ndpts').value + " scored "
document.getElementById('hiddenresult').value += document.getElementById('secondscore').value + " for "
document.getElementById('hiddenresult').value += document.getElementById('secondwkts').value + " in "
document.getElementById('hiddenresult').value += document.getElementById('limit2').value + " overs.";
}
// alert(document.getElementById('hiddenresult').value)
var rtn = confirm('Is the following correct?\n' + document.getElementById('hiddenresult').value);
return rtn;
}

function validate()
{
if(document.getElementById("Dateplayed").selectedIndex == 0)
{
alert("You must select Match Date from list");
document.getElementById('Dateplayed').focus();
return false;
}

if(document.getElementById("Matchtype").selectedIndex == 0)
{
alert("You must select a Match Type");
return false;
}

if(document.getElementById("Matchstatus").selectedIndex == 0)
{
alert("You must select a Match Status");
document.getElementById('Matchstatus').focus();
return false;
}

// ***********
// Added April 2004 Gwr Start tag
matchStatusvar=document.getElementById('Matchstatus').value;
if (matchStatusvar=='Completed') {

if(document.getElementById("Batfirst").selectedIndex == 0)
{
alert("You must select a Side from Select Team 1 list");
document.getElementById('Batfirst').focus();
return false;
}

if (document.getElementById("Batfirstpts").selectedIndex == 0)
{
alert("You must select Pts from list");
document.getElementById('Batfirstpts').focus();
return false;
}

if(document.getElementById("firstwkts").selectedIndex == 0)
{
alert("You must select Wkts from list");
document.getElementById('firstwkts').focus();
return false;
}

if(document.getElementById("Bat2nd").selectedIndex == 0)
{
alert("You must select a Side from Select Team 2 list");
document.getElementById('Bat2nd').focus();
return false;
}


if(document.getElementById("Bat2ndpts").selectedIndex == 0)
{
alert("You must select Pts from list");
document.getElementById('Bat2ndpts').focus();
return false;
}

if(document.getElementById("secondwkts").selectedIndex == 0)
{
alert("You must select Wkts from list");
document.getElementById('secondwkts').focus();
return false;
}

if(document.getElementById('Batfirst').value == document.getElementById('Bat2nd').value)
{
alert('Both sides selected cannot be the same.');
document.getElementById('Batfirst').focus();
return false;
}

// required field start
firstScorevar=document.getElementById('firstscore').value;
if (firstScorevar=='') {
alert('First Score is a required field. Please enter runs scored.');
document.getElementById('firstscore').focus();
return false;
}
// required field end

// required field start
secondScorevar=document.getElementById('secondscore').value;
if (secondScorevar=='') {
alert('Second Score is a required field. Please enter runs scored.');
document.getElementById('secondscore').focus();
return false;
}
// required field end

if(document.getElementById("spanTeam1").style.display == 'none')
return true;

var limit1Val = document.getElementById('limit1').value;
var limit2Val = document.getElementById('limit2').value
var uLimit = 40;


// required field start
Overs1var=document.getElementById('limit1').value;
if (Overs1var=='') {
alert('Overs for First Team is a required field. Please enter overs faced.');
document.getElementById('limit1').focus();
return false;
}
// required field end

// required field start
Overs2var=document.getElementById('limit2').value;
if (Overs2var=='') {
alert('Overs for Second Team is a required field. Please enter overs faced.');
document.getElementById('limit2').focus();
return false;
}
// required field end

if(document.getElementById('Matchtype').value == 'Sat Lge')
uLimit = 45;
else if(document.getElementById('Matchtype').value == 'Eve Lge')
uLimit = 20;
else
uLimit = 40;

if(parseInt(limit1Val) != 'NaN')
{
if(parseInt(limit2Val) != 'NaN')
{
if((limit1Val < 0) || (limit1Val > uLimit))
{
alert('Overs must be in the range of 0 to ' + uLimit + '.');
document.getElementById('limit1').focus();
return false;
}
else if((limit2Val < 0) || (limit2Val > uLimit))
{
alert('Overs must be in the range of 0 to ' + uLimit + '.');
document.getElementById('limit2').focus();
return false;
}
}
else
{
alert('Limit2 is not a number');
document.getElementById('limit2').focus();
return false;
}
}
else
{
alert('Limit1 is not a number');
document.getElementById('limit1').focus();
return false;
}




var firstVal = document.getElementById('firstscore').value;
var secondVal = document.getElementById('secondscore').value
if(parseInt(firstVal) != 'NaN')
{
if(parseInt(secondVal) != 'NaN')
{
if((firstVal < 0) || (firstVal > 500))
{
alert('Firstscore must be in the range of 0 to 500.');
document.getElementById('firstscore').focus();
return false;
}
else if((secondVal < 0) || (secondVal > 500))
{
alert('Secondscore must be in the range of 0 to 500.');
document.getElementById('secondscore').focus();
return false;
}
}
else
{
alert('Secondscore is not a number');
document.getElementById('secondscore').focus();
return false;
}
}
else
{
alert('Firstscore is not a number');
document.getElementById('firstscore').focus();
return false;
}
return true;
}


}

</SCRIPT>

Willy Duitt
04-14-2004, 03:00 PM
Originally posted by westrey
Willy,

I only want to perform the checks in the function validate() if matchstatus='Complete'
otherwise I need to concatenate a literal string to the teams selected after ensuring the fields required for matchstatus='Complete' are not displayed. Please run the javascript shown between
tags below with the html I posted when I opened up this thread for more info.

Thanks for the tip about the [code] tags. I didn't know I was suppose to look there. :rolleyes:

I'm sorry but I can not help you. I am not inclined to take various code snippets from several of your posts and put a puzzle together. Besides, I still can not understand the problem other than checking if a value is present and I already answered that question. Use indexOf() or you could also use match()....

.....Willy