ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 7th, 2003, 04:56 PM
VJ29 VJ29 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 2 VJ29 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #2  
Old December 7th, 2003, 06:52 PM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 6
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..

Reply With Quote
  #3  
Old December 7th, 2003, 07:31 PM
VJ29 VJ29 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 2 VJ29 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old December 7th, 2003, 08:22 PM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > error with onclick after using forum thread


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT