473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

functions in Javascript

16 New Member
I have a few text fields and a button in a .JSP page. The button has an onclick value of "buttonclick()". I want it to complete the lines inside of the buttonclick() function that I have defined when the user clicks the button.

For some reason, the lines are run as soon as the page loads. Here is the code I have. The user is immediately forwarded to the Login servlet rather than being able to enter information in. I cannot use a <form>, because I need to save the information in the current session.

In the <head>:
[HTML]<script type="text/javascript">
function buttonclick(){
<%
//some lines of code, then these three lines to forward some information on to the login servlet.
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/servlet/Login");
rd.forward(request, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="buttonclick()" name="submitButton" value="Login" />[/HTML]
Jun 15 '07 #1
3 2164
dmjpro
2,476 Top Contributor
I have a few text fields and a button in a .JSP page. The button has an onclick value of "buttonclick()". I want it to complete the lines inside of the buttonclick() function that I have defined when the user clicks the button.

For some reason, the lines are run as soon as the page loads. Here is the code I have. The user is immediately forwarded to the Login servlet rather than being able to enter information in. I cannot use a <form>, because I need to save the information in the current session.

In the <head>:
[HTML]<script type="text/javascript">
function buttonclick(){
<%
//some lines of code, then these three lines to forward some information on to the login servlet.
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/servlet/Login");
rd.forward(request, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="buttonclick()" name="submitButton" value="Login" />[/HTML]

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     //some lines of code, then these three lines to forward some information on to the login servlet.
  3.     ServletContext sc = getServletContext();
  4.     RequestDispatcher rd = sc.getRequestDispatcher("/servlet/Login");
  5.     rd.forward(request, response);
  6. %>
  7.  
This tag is not valid in javascript code .... right????
Write valid JS code inside the function body.
Best of luck......

Kind regards,
Dmjpro.
Jun 15 '07 #2
r035198x
13,262 MVP
I have a few text fields and a button in a .JSP page. The button has an onclick value of "buttonclick()". I want it to complete the lines inside of the buttonclick() function that I have defined when the user clicks the button.

For some reason, the lines are run as soon as the page loads. Here is the code I have. The user is immediately forwarded to the Login servlet rather than being able to enter information in. I cannot use a <form>, because I need to save the information in the current session.

In the <head>:
[HTML]<script type="text/javascript">
function buttonclick(){
<%
//some lines of code, then these three lines to forward some information on to the login servlet.
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/servlet/Login");
rd.forward(request, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="buttonclick()" name="submitButton" value="Login" />[/HTML]
You are writing Java code inside Javascript tags. That won't work. Submit the form using Javascript not using request dispatcher.
Jun 15 '07 #3
wesomon99
16 New Member
thank you both for your help, I..umm...didn't know I couldn't do that.
Jun 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3385
by: George Ziniewicz | last post by:
.. I have an html file with javascript functions in the <head> section that work fine when called from events or instanced as objects. When I move the functions to an external js file they don't...
9
1957
by: relaxedrob | last post by:
Howdy All! I am still getting my head around a few base concepts. Any comments or criticisms on the below definitions would be most welcome! A function is an object. JavaScript objects have...
17
3589
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
3
3911
by: Nikki | last post by:
Hi, I would like to create a central storage place for javascript functions that I can then access from any of my asp.net projects. An example of what I need it for is as follows: I have a...
10
2442
by: Tony Rice | last post by:
If I've loaded a set of functions in a webdocument like this: <script language="JavaScript" type="text/javascript" src="/js/foo.js"</script> Shouldn't I be able to call a function from...
1
1428
by: Liam | last post by:
We recently decided to go from cookieless to cookies, changing web.config to read cookieless=false. Since making that change, I've noticed that javascript functions kept in included libraries...
3
4046
by: Shailesh Humbad | last post by:
I compiled this article on trim functions for Javascript: Javascript Trim LTrim and RTrim Functions http://www.somacon.com/p355.php If you have any comments, please let me know. Thanks,...
4
1564
by: Daniel | last post by:
Hi, I was reading Douglas Crockford's article on prototypal inheritance at http://javascript.crockford.com/prototypal.html. I think it also relates to a post back in Dec 2005. The mechanism...
12
10869
by: thegman | last post by:
Hi all, I'm trying to get list of JavaScript methods/functions in a script file in much the same a good text editor will, the difference being that I need to output it to a file or stdout, or some...
5
1169
by: James | last post by:
Hello. I have a problem trying to get seperate image functions to work together. Starting with the img tag and associated html: <img src="image1.jpg" NAME="theImage" pbsrc="image1_lrg.jpg"...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.