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

Onclick Event of HTML Button

Status
Not open for further replies.

wwworg

Programmer
Feb 10, 2006
35
CA
Hey guys

When I make a button in HTML and put some Java code in the "onclick" event. When I load the form, the code in "onclick" events gets executed, even though I have not clicked the button.

How come???

Here's the code

Code:
	<BUTTON TYPE=button Value = "Click" ID=toggler ONCLICK="<% 

DbRes sendID = dbc.executeSelectQuery(
"SELECT EMAIL_ADDR "
+ "FROM USER"
+ "WHERE user.id = 'tester'"
);
%>"> run this select statement
</BUTTON>

[\code]

and then when I click the button, the code doesnt run??? dont know why... even though the code is declared in "onclick" event it should run when I click the button.

Any thoughts??
 
Are you trying to run server-side code in a client-side event handler? You can put javascript (not java, that's entirely different thing) in onclick event but not your server side code. The latter will get executed when the page loads, not when you push the button. It is the nature of web applications.
 
This question belongs in the JSP or ASP forum, but I'm sure it's been asked there before, so I'll take a stab at a short answer:

You're thinking of things backwards. When the page draws, the Java is executed and the end-result is an HTML page which is posted to your browser. If you view the source of the final HTML page, you will not see the Java there.

I'm sure everyone wishes they could do what you are trying to do here, but you need to take a more round-about approach to it. Go to the JavaScript Forum and say "someone said I can't do this... ...but that I could approach this with JavaScript" and ask for assistance.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top