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!

OnClick Command

Status
Not open for further replies.

Andel

Programmer
Feb 15, 2001
366
0
0
US
Hi All,
Is there a OnClick command in ASP?
Basically what I want to do is to execute an asp function when they click on the submit button on my form.

Ideas? Suggestions?

Thanks!

Andel
andel@barroga.net
 
onClick is a client side command/script. ASP is server side only and is not connected to the client side in any way other than receiving or submitting data to the client upon page refresh/transfer. The only way you can get server data upon a click of a button or link or anything is to transfer the page....even if it's to itself. (except unless you use remote scripting...which I personally haven't messed with at all yet). -Ovatvvon :-Q
 
Or you can submit the page on clicking the button and then
execute the function in the target page. Rushi Shroff Rushi@emqube.com
"Life is beautiful."
 
What I had is a Riddle page. I can put the Riddles as well as their Answers into a recordset. I also can display a Random riddle and a text box prompt to enter the answer.

What I want to do is after they put the answer, they click the submit button. A function will then check if the answer is correct or not by reading the recordset (if possible). Is there a way you can do this?

If not, can I mix .asp and javascript together in one page? Because I know that javascript has an OnClick function.

Thanks,






Andel
andel@barroga.net
 
I get the feeling you still don't understand the difference between client and server side code. Here is the logic of how it will have to work...

When the user goes to the web site, the server get's the riddle from the database, sends it to the user along with all the other client side code such as html and javascript. that is no longer connected to the server and is sent to the user formed to make the web page that everyone see's. Now they're looking at a web page with a riddle on it. You have a form/text box waiting for their answer...they enter it into the text box and hit the submit button. The web page sends the user's answer back from their machine to the server...the server then compares their answer to the answer you have in the database...depending on whether it matches or not, it'll perform the action you want it to based on the outcome of the conditional statement you made on the server side code (ASP).

Then, you can redirect them to another page, or send back the same page again...send them somthing like: "Your answer was correct" or somthing back along with the html and javascript, or xml, or what-have-you which will be the client side code because it's not connected to the server...it has already been sent to the user/client and has nothing to do with the server again until the user/client resends the page again or refreshes it, or whatever.

Does that clarify it a little?
-Ovatvvon :-Q
 
Using Remote scripting you can execute server side ASP function. For more information look at msdn.microsoft.com and look in to "Remote Scripting" section
 
Ovatvvon:
So, that means 1 riddle will have 2 roundtrips to the server? First to retrieve and display the riddle and second to compare the answer?

Visitor:
I look into that.
Andel
andel@barroga.net
 
The first time will happen when the user goes to your site initially. The first time to the site, your site will pull data and send it to the client with the riddle from the database. Whether you're serving data (a riddle) from the database or not, that will be one trip to the server as with any web site on the internet.

Now, when the user submits the answer to the question, you can process the answer, and get the next question at the same time, send the results of their answer (correct or incorrect) and the next riddle at the same time.

make sense? -Ovatvvon :-Q
 
Andel,

Maybe you can try this snippet code:

<%
' For example the file name is thissite.asp

act = request(&quot;act&quot;)
if isEmpty(act) then
act = &quot;act1&quot;
end if

select case act
case &quot;act1&quot;
act1
case &quot;confirm&quot;
confirm
end select

sub act1
%>
<form action=thissite.asp?act=confirm>
<input type=text name=abc>
<input type=submit value=&quot;Submit&quot;>
</form>
<%
end sub
' where abc is the text box that contains the answers in html page

sub confirm
%>
answer = request(&quot;abc&quot;)
<%
' then in this sub you can compare variable answer with the answer in your database
end sub
%>

Hope this helps.

Vincent.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top