|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
error with onclick after using forum thread
Hi,
I have this code which converts a number given in the first textfield into a grade i.e. pass, fail, when the convert button is clicked, and inserts it into the result textfield. My problem is that when the procedure is called and the form resubmits the result textfield doesn't have the valuie in it. When the from is submitted the onclick=result.value line becomes e.g onclick=result.value="Fail" (if this 0<grade<=40). This means that the button has to be re clicked to make the text appear in the result field. Any help around this would be appreciated as i used the answer from another thread on using onclick but i still have this problem. Thanks for your time and help in advance. Here is the code: <html> <head> <% sub Convert_onclick() dim i i=request.QueryString("first") if (i="") then elseif (i>=0 and i<40) then response.write("Fail") elseif (i>=40 and i<=49) then response.write("Third") elseif (i>=50 and i<=59) then response.write("L. Second") elseif (i>=60 and i<=69) then response.write("U. Second") elseif (i>=70 and i<=100) then response.write("First") elseif (i>100) then response.write("0<= Grade <=100") end if end sub %> </head> <body> <form name="calculator" action="Qs1.asp" method="get"> Enter first number: <input type="text" name="first"> <br>Enter second number: <input type="text" name="second"> <br>Result: <input type="text" name="result"> <br> <input type="submit" name="convert" value="Convert" onclick=result.value="<% Convert_onclick() %>"> </form> </body> </html> |
|
#2
|
|||
|
|||
|
you can't do that in ASP (.net is a different story)
the onClick method is used for calling javascript functions and such. because of the way ASP works, your call to Convert_onClick() is being executed before the page is actually sent back to your browser another problem is that when calling subs you _cannot_ use paranthesis _unless_ you prefix the word "Call" before you actually call the sub, so "Convert_onClick()" would cause an error where as "Call Convert_onClick()" would not... though you can just put "Convert_onClick". you'll have to do one of two things 1) have the form submit the information to itself then process the information and print out the result or make it submit the information to a seperate page which could then process and print out the result.. either way it's the same process or 2) create a javascript function that reads in the values from "first" and "second" and does the required calculations then prints the result or pops up a message box with the result, something. if you'd like to be able to respond to events (eg, onClick) you'll have to use ASP.net unless you wanna do some inventive coding and half-way handle events.. |
|
#3
|
|||
|
|||
|
This question is actually part of an exercise.
The first exercise is to create two textfields called first and result and a submit button called convert on a form. When the submit button is clicked on a sub procedure should be invoked which converts the value in the first texfield to a grade in text i.e. pass, fail etc. This grade should then be inserted into the result textfield to show the user the converison. This is what i am tyring to do in Convert_onclick(). I need to figur out how i could invoke the sub-procedure when the button is clicked and insert the output of the sub-procedure into the result textfield. Thanks for your reply UncleFu. |
|
#4
|
|||
|
|||
|
mmmk
so keep your form how it is, i'm guessing that Qs1.asp is the file with the form in it. get rid of the onClick=... from the <input type="submit"...> line Code:
<%
Function checkGrade(grade)
If grade >= 40 then
checkGrade = "Fail"
elseif grade >=50 then
checkGrade = "Third"
else
checkGrade = ""
end if
end function
grade = request.form("first") 'request grade amount
%>
then make the code for your result text box look like this Code:
<input type="textbox" name="result" value="<%= checkGrade(grade)%>"> 1. The user loads the page and enters an amount into the First textbox 2. User clicks submit 3. Page reads in the value the user entered 4. The value of the result textbox is the result returned by calling the checkGrade() function and passing the grade variable to it. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > error with onclick after using forum thread |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|