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!

Select box, form validations

Status
Not open for further replies.

newbby

Programmer
Mar 16, 2004
36
US
Hi,
Please help me figure, how to write this form validations in javascript.
when a user selects the value "ON" from a select drop down list,
I have to figure that the sum of all the intWorkDone should be <=200.

<form action="update.cfm" method="post">

<cfoutput>
<cfloop from="1" to="#queryName.recordcount#" index="i">

<input type="text" name="StrName" value="#queryName.Name#">

<select name="strSelect">
<option value="ON">ON
<option value="OFF">OFF
</select>

<input type="text" name="intWorkDone" value="#queryName.WorkValue">

<input type="submit" name="" value="Update">

</cfloop>
</cfoutput>
</form>

Thanks
 


<form action="update.cfm" method="post">
<script>
function SubmitForm(){
var sum = 0;
var i = 1;
var obj = document.getElementById("WorkDone_"+i);
while(obj){
i++;
sum += obj.value;
obj = document.getElementById("WorkDone_"+i);
}
if(sum < 200){
alert('Sum must be more than 200');
return false;
}else document.forms[0].submit();
}
</script>


<cfoutput>
<cfloop from="1" to="#queryName.recordcount#" index="i">

<input type="text" name="StrName" value="#queryName.Name#">

<select name="strSelect">
<option value="ON">ON
<option value="OFF">OFF
</select>

<input id="WorkDone_#i#" type="text" name="intWorkDone" value="#queryName.WorkValue">

<input type="button" name="" value="Update" onclick="SubmitForm()">

</cfloop>
</cfoutput>
</form>


 
Thanks vladibo for the solution. I need to sum only those intWorkDone records, where the strSelect= ON. Your solution is missing that catch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top