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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have two pages: the first is a

Status
Not open for further replies.

irate

Programmer
Jan 29, 2001
92
GB
I have two pages:

the first is a form with a textbox and submit button. and the second is an asp that checks the values of the form.

if someone puts anything but a number in the textbox i want to convert it to an int so i use the following code:

<input type=&quot;text&quot; name=&quot;price&quot;>

<%

price = request.form(&quot;price&quot;)
price = Cint(price)

%>

BUT this is giving me the error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'Cint'
search.asp, line 8


Can anyone tell me what im doing wrong?
 
what is the value in request.form(&quot;price&quot;)?

sounds like price is spaces or null
 
Sounds like your basic understanding of what cInt does and how it's used it off just a bit.

Cint will take this:

&quot;87&quot;

and turn it into a variant of subtype integer, so you then have

87

BUT... cInt will always return an error if there are characters in there, so that this:

&quot;hello, I'm a string&quot;

will never convert. So if there are any characters in there (a dollar sign, for instance), and you try to cInt() it, you get the error.

An alternative might be to use client side checking to make sure that what was entered is a number. It's easy enough.

<script language=javascript>
function checkForNumber(var){
if (isNaN(var)){
alert('You must enter only a number!');
document.formName.price.value = '';
return false;
}
return true;
</script>

<input type=text name=price onBlur=&quot;checkForNumber(this.value);&quot;>
penny.gif
penny.gif
 
Missed my closing } on that function there, so if you're copying and pasting, it should be:

function checkForNumber(var){
if (isNaN(var)){
alert('You must enter only a number!');
document.formName.price.value = '';
return false;
}
return true;
}

:)
paul
penny.gif
penny.gif
 
Thanks very much, i thought that might be the problem.
Is there no way i can convert a string to a number?

or maybe if it is anything apart from 0 to 9 change whatever it is to 0 ?
 
If IsNumeric(request.form(&quot;price&quot;) = False Then
price = 0
Else
price = request.form(&quot;price&quot;)
End If
 
oops! forgot ending paren -

If IsNumeric(request.form(&quot;price&quot;)[colr red])[/color] = False Then
 
second oops, typo...

If IsNumeric(request.form(&quot;price&quot;)) = False Then


too bad we can't delete our mistyped responses.......

:~/

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top