View Single Post
  #6 (permalink)  
Old February 27th, 2006, 07:18 PM
mat41 mat41 is offline
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

My JS is average but I found your objective useful for me to have a go. Try:

----cut n paste code: name your page addScoreswithJS.asp-----
<html>
 <head>
  <title>calculate client side values</title>
  <script>
  function validateScores()
  {
     if(document.theForm.s1.value == "")
     {
        alert("Please enter a score in box one");
        document.theForm.s1.focus();
        document.theForm.s1.select();
        return(false);
     }
     if(isNaN(parseInt(document.theForm.s1.value)))
     {
        alert("The value in box one must be an integer");
        document.theForm.s1.focus();
        document.theForm.s1.select();
        return(false);
     }
     if(document.theForm.s2.value == "")
     {
        alert("Please enter a score in box two");
        document.theForm.s2.focus();
        document.theForm.s2.select();
        return(false);
     }
     if(isNaN(parseInt(document.theForm.s2.value)))
     {
        alert("The value in box two must be an integer");
        document.theForm.s2.focus();
        document.theForm.s2.select();
        return(false);
     }
     document.theForm.posted.value = "y";
     return(true)
  }

  function addScores(scoreValue)
  {
     var scoreOne;
     scoreOne = (scoreValue);
     parseInt(scoreOne);
     parseInt(document.theForm.RunningTotal.value);
     (document.theForm.RunningTotal.value = (document.theForm.RunningTotal.value + parseInt(scoreOne)));
  }

  function resetValues()
  {
     document.theForm.s1.value='';
      document.theForm.s2.value='';
     document.theForm.RunningTotal.value='';
     document.theForm.posted.value = '';
  }
  </script>
 </head>
<body>
<%
   if request.form("posted") = "y" then
      response.write "<b>The form has been posted - your total is " & request.form("RunningTotal") & "</b>"
   else
      response.write "<B>Enter scores - the last box should calculate and display the runing total.</b>"
   end if
%>
<form name="theForm" method="post" action="addScoreswithJS.asp" onsubmit="return validateScores();">
<input type="hidden" name="posted" value="">
<table>
 <tr>
  <td>Score One:</td>
 </tr>
 <tr>
  <Td><input type="text" name="s1" value="<% if request.form("s1") <> "" then response.write request.form("s1") end if %>" size="5"></td>
 </tR>
 <tr>
  <td>Score Two:</td>
 </tr>
 <tr>
  <Td><input type="text" onClick="javascript:addScores(document.theForm.s1. value);" value="<% if request.form("s2") <> "" then response.write request.form("s2") end if %>" name="s2" size="5"></td>
 </tR>
 <tr>
  <td><B>Running Total</b></td>
 </tr>
 <tr>
  <td><input type="text" name="RunningTotal" value="<% if request.form("RunningTotal") <> "" then response.write request.form("RunningTotal") end if %>" size="5"></td>
 </tr>
 <tr>
  <td><input type="submit" name="Submit" onClick="javascript:addScores(document.theForm.s2. value);">&nbsp;&nbsp;<INPUT type="button" value="Reset Values" onClick="resetValues();"></td>
 </tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------------

Wind is your friend
Matt