Web Hosting Talk







View Full Version : asp error help - Type mismatch


hoachen
03-23-2006, 10:57 AM
I am pretty new to ASP and I got this type mismatch problem when I press the submit button. I set the textbox of user to type in the number from 0 to 100. When the user press the submit button this two textboxes infor will email to my email account. I am using asp to do that. Please my asp code below.

Here is the HTML
<tr>
<td colspan="6" class="whiteText">PED
<input type="text" size="10" name="myInput" onKeyUp="writeMessage()" id="myInput" />% and Adult:
<input type="text" size="10" name ="mySecondInput" onKeyUp="writeMessage()"/>%</td>
</tr>

ASP. (I COULDN'T USE REQUESTION.FORM FOR MY SECOND INPUT BECAUSE IT AUTOMATICALLY FILLED IN WHEN THE FIRST BOX THE VALUE IS TYPE SO I AM USING DECLARE A VARIABLE AND THE USING 100 TO MINUS WHAT THE USER INPUT TO GET MY SECOND VALUE. CAN YOU SPOT THE ERROR? PLEASE HELP

dim adult

adult = 100 - REQUEST.FORM("myInput")

IF REQUEST.FORM("myInput") <> "" THEN
message = message & "<br> <b> Patient Mix: PED: </b>" & REQUEST.FORM("myInput2") & "%" & "<b>Adult: </b>" & adult & " % &nbsp; &nbsp;"
ELSE
message = message & "<br> <b> Patient Mix: PED: </b> N/A " & "&nbsp; &nbsp;" & " <b> Adult: </b> N/A "
END IF

jimpoz
03-23-2006, 11:26 AM
dim adult

adult = 100 - REQUEST.FORM("myInput")

IF REQUEST.FORM("myInput") <> "" THEN
message = message & "<br> <b> Patient Mix: PED: </b>" & REQUEST.FORM("myInput2") & "%" & "<b>Adult: </b>" & adult & " % &nbsp; &nbsp;"
ELSE
message = message & "<br> <b> Patient Mix: PED: </b> N/A " & "&nbsp; &nbsp;" & " <b> Adult: </b> N/A "
END IF

I would probably put
adult = 100 - REQUEST.FORM("myInput")
between the "If" and "Else" statements, once it's been established that that form variable has a value. You may also want to use isnumeric() to validate that the value is a number before you perform any arithmetical functions.

Also, it's not clear from your code, but you can only use request.form if you are the method of the form is POST. If you're using GET, then you have to change the code to use request.querystring. If you don't specify, it will default to GET. If you're not sure, this code will let you know where the form values are:

for each x in request.form
response.write "request.form(""" & x & """) = """ & request.form(x) & """<BR>"
next
for each x in request.querystring
response.write "request.querystring(""" & x & """) = """ & request.querystring(x) & """<BR>"
next

hoachen
03-23-2006, 11:55 AM
alright, it works now, thank you for your very good advice! After I placed adult = 100 - REQUEST.FORM("myInput") between the if else if works without error!
thank you very much
Cheer,
hoachen


I would probably put
adult = 100 - REQUEST.FORM("myInput")
between the "If" and "Else" statements, once it's been established that that form variable has a value. You may also want to use isnumeric() to validate that the value is a number before you perform any arithmetical functions.

Also, it's not clear from your code, but you can only use request.form if you are the method of the form is POST. If you're using GET, then you have to change the code to use request.querystring. If you don't specify, it will default to GET. If you're not sure, this code will let you know where the form values are:

for each x in request.form
response.write "request.form(""" & x & """) = """ & request.form(x) & """<BR>"
next
for each x in request.querystring
response.write "request.querystring(""" & x & """) = """ & request.querystring(x) & """<BR>"
next