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

error detection and correction

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
0
0
GB
currently I have an asp data entry page that takes in input from text boxes and another one that process the data from the text boxes. Is there any way in asp/javascript that I can check/detect if the text boxes on the data entry page have text in them or have an integer in them. And if they don't for example have integer value typed in the text box then take them back to the data entry page?<br><br>I hope that makes sense, grateful for any help given.<br>&nbsp;
 
There are two possibilitys of testing the data which user entered.<br>&nbsp;1. using vbscript/ASP, You can use isNumeric(data to be checked). It returns true if the entered data can be converted into numric format.<br><br>&nbsp;&nbsp;2. Using JavaScript, use javascript isNaN(data to be checked) function. isNaN function is case censitive. It returns true if the entered data is a number
 
taval:<br><br>You can write your own client-side function either in javascript or vbscript. Use this fuction onblur event of input tag. <br><br>You will get error as soon as you coming out the respective input tag.<br><br>Anand <p>Anand Mishra<br><a href=mailto:anandm@entcomm.com>anandm@entcomm.com</a><br><a href= > </a><br>
 
The thing is a want to check in asp whether the text box contains a numeric value, how would I do this?. I want to check if its a integer then do this else do something else.<br>How do I do this in asp, for example take the name of the text box to be CustNum.<br><br>grateful for any help, thankz.<br><br>
 
You can do this either server or client side (or both if you really need extra security). Here are some suggestions...<br><br>CLIENT SIDE USING JAVASCRIPT:<br><br>The text box has a name which you use in javascript to get its contents. For example, let's say the name of your text box is &quot;numbersonly&quot; and the form is named &quot;theform&quot;. You can get the value in the box by writing:<br><br>thevalue = document.theform.numbersonly.value;<br>or more explicitly:<br>thevalue = document.forms[&quot;theform&quot;].elements[&quot;numbersonly&quot;].value;<br><br>So you can check this value when the user submits the form, or when the user leaves the box (which is the onBlur handler referred to above). I don't use the onBlur very often so I will do this with onSubmit. So you have your form and in the form tag you call a javascript function with an onSubmit. The called function retrieves the value of the &quot;numbersonly&quot; box. If it is not numeric, it sends an alert and returns false which prevents the form from submitting. Otherwise, it returns true and the form submits. You might have to tweak this depending on the browser. Anyways, the following works on my computer ok.<br><br><font color=red><br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;script language=&quot;JavaScript&quot;&gt;<br>function validateNumeric() <br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;var check = isNaN(document.theform.numbersonly.value);<br>&nbsp;&nbsp;&nbsp;&nbsp;if (check ¦¦ document.theform.numbersonly.value==&quot;&quot;) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;please enter a numeric value...&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;return true;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;...&quot; method=post onSubmit=&quot;return validateNumeric();&quot; name=&quot;theform&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=text value=&quot;&quot; name=&quot;numbersonly&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=submit&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br></font><br><br><br>SERVER SIDE USING ASP:<br><br>From asp you would write&nbsp;&nbsp;at the top of your RECEIVING page, after any page directives but <i>before</i> you write any page content or insert anything in any databases, something like:<br><br><font color=red>valuetocheck = request.FORM(&quot;CustNum&quot;)<br>if NOT isNumeric(valuetoCheck) then<br>&nbsp;&nbsp;&nbsp;&nbsp;response.redirect(&quot;previouspage.asp?errmsg=notnumeric&quot;)<br>end if</font><br><br>then in your form page there should be a piece of asp code which checks for the querystring key &quot;errmsg&quot; and if it is equal to &quot;notnumeric&quot; then write a note to the user (or even a javascript prompt).<br><br>Hope there's something here of use. <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
I have typed in the following code into my asp script: <br><br>---------------------------------------<br>Select Case strAction<br><br> Case &quot;CustID&quot;<br> valuetocheck = request(&quot;SQLvariable&quot;)<br> if NOT isNumeric(valuetocheck) then<br> response.redirect(&quot;webdb.asp&quot;)<br> response.end<br>&nbsp;&nbsp;&nbsp;&nbsp; end if<br> StrQuery = &quot;Select * from Customer where CustID = &quot; & Cint(Request(&quot;SQLvariable&quot;))& &quot;&quot;<br><br> Case &quot;CustName&quot;<br>..........<br>..........<br>---------------------------------------<br><br>I know it works when I type in an integer, but when I type in letters , I get the following error :<br><br>---------------------------------------------------<br>Response object error 'ASP 0156 : 80004005' <br><br>Header Error <br><br>/webdb.asp, line 95 <br><br>The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content. <br>---------------------------------------------------<br><br>The error relates to the line of code :<br>response.redirect(&quot;webdb.asp&quot;)<br>in the code.<br>The asp page I execute this from is called webdb.asp, so bascially I just want it to return to the same page, I have tried redirecting to other pages but this also does not work. Does anyone know what the problem is??<br><br>I would be grateful for any help.<br>thankx<br><br><br><br><br><br><br>
 
I'm not an expert on the http protocol as it relates to asp but usually this error happens because you have written page content <i>before</i> trying to redirect. That's why the redirect has to be at the top of the page or at least before any response.write statements or ordinary text content. Following this rule, I've used redirects in many many pages and have never had problems. (There's also server.transfer which is supposedly faster by the way but it's in the later versions of asp only).<br><br>Examples:<br><br><font color=red>response.write(&quot;hello&quot;)<br>response.redirect(&quot;somepage.asp&quot;)</font><br><br>will give you an error.<br><br><font color=red>&lt;HTML&gt;<br>&lt;HEAD&gt;&lt;/HEAD&gt;<br>&lt;%<br>response.redirect(&quot;somepage.asp&quot;)<br>%&gt;</font><br><br>will also give you an error.<br><br>Also, modifying the response object before a redirect by writing something like <br><br><font color=red>reponse.buffer = true<br>response.redirect(&quot;somepage.asp&quot;)<br></font><br><br>I believe will also give you an error. However, any page directives like &lt;%@EnableSessionState=false%&gt; or whatever usually go before everything else including the redirect. Your error message says line 95, which sounds like it's pretty far down the page and there's probably some output before this which might be causing the error.<br><br>See if this helps. Also, if your redirect is working properly, I'm not sure you need the response.end, but that's up to you.&nbsp;&nbsp;By the way, what's wrong with doing this client side? <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top