
May 7th, 2000, 12:56 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
|
<i><b>Originally posted by : Jeff (jbrewer22026@home.com)</b></i><br />I'm having some difficulty trying to understand precisely what you need here, but thought I'd throw out a couple general observations and maybe that will help. If you'd like you may contact me at jbrewer22026@home.com.<br /><br />with respect to nsa1 and nsa2 adding up to 100...<br />is there any chance the user will enter non-numeric characters in the form? e.g. could they enter "50%" instead of "50"? this could be a problem. Anything that comes back from an input box is going to be a string...in doing calculations I've found it helpful to force (or attempt to force) the values to numeric variables first (e.g. nsa1 = request.form("NSA1") + 0) Of course this is going to cause an error if request.form("NSA1") has any non-numeric characters. You could do something like<br /><br />If IsNumeric(request.form("NSA1")) Then<br /> nsa1 = request.form("nsa1") + 0<br />Else<br /> [some code to ask the user to enter numeric data]<br />End If<br /><br />Your If..then..else statement looks a little odd to me. Would this work?...<br /><br />If nsa1 + nsa2 <> 100 Then<br /> Response.write "the values for the question.."<br />End If<br /><br />As for the radio buttons, why not preselect one on the form so that it can't return nothing? <br /><br /><br /><br /><br />------------<br />Kevin at 5/4/2000 1:59:00 PM<br /><br />Hello I am trying to do a survey for school and people who are doing the questions want <br />it to do a validation on two type of question. I do not know vbscript that well<br />only what I have read in books. Thanks for any help I am in a bind here. If there is a better <br />way to do this let me know.<br /><br />1) The first kind of question is where the person enters percentages that need to calulate to<br />100%. If they skip the whole question that is fine but if they do enter answer the total must be<br />100%. If it does not gets a response saying the question yada yada yada has answers that do<br />not equal to 100%. There are about 10 of these kind of question on the survey.<br /><br />Here is the code I came up with for that one<br /><br /><SCRIPT LANGUAGE="VBScript"><br /><br /><br /> Dim nsa1<br /> Dim nsa2<br /><br /> nsa1 = request.form("NSA1")<br /> nsa2 = request.form("NSA2")<br /> <br />'This check to make sure that if the whole question was skipped that it does not tell them<br /> that the question was skipped. It then checks to make sure that if the answers do not equal<br /> to 100 percent it will give an error message.<br /><br /> If NSA1 + NSA2 = 0 Then<br /> End If<br /> Else <br /> NSA1 + NSA2 <> 100 Then<br /> Response.Write "The values for the question: Yada Yada Yada do not equal to 100 please go back and correct your answers.<br /> Else<br /> End If<br /><br />2) The second kind of qestion just checks for radio buttons that are left blank by accident, <br />because alot of question we are using are radio buttons. It is easy to think you have clicked on <br />something and you really didn't.<br /><br />YSD1 = request.form("YSD1")<br /> <br /> If IsBlank(YSD1) = True Then<br /> Response.Write = "You let the question: Yada Yada Yada blank if you want to go back click the back button on your browser.<br /> End If<br /></SCRIPT>
|