473,739 Members | 9,109 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 = getServletConte xt();
RequestDispatch er rd = sc.getRequestDi spatcher("/servlet/Login");
rd.forward(requ est, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="button click()" name="submitBut ton" value="Login" />[/HTML]
Jun 15 '07 #1
3 2180
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 = getServletConte xt();
RequestDispatch er rd = sc.getRequestDi spatcher("/servlet/Login");
rd.forward(requ est, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="button click()" name="submitBut ton" 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 = getServletConte xt();
RequestDispatch er rd = sc.getRequestDi spatcher("/servlet/Login");
rd.forward(requ est, response);
%>
}
</script>[/HTML]

And then in the <body>:
[HTML]<input type="button" onclick="button click()" name="submitBut ton" 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
3405
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 work (timers don't run). What pitfalls are there in having "external" functions, is there a scope problem like in c?
9
1966
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 properties: - a var (which is an object or a primitive); - a method (which is a function assigned to the object).
17
3625
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 deep. In that case you need much more ram than a PC has to store functions calculated in loops so that you do not have to recalculate every time you cycle through the nest of loops. Using a HD for storage to extend ram is much too slow for many...
3
3939
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 class library that contains a function I use all the time (to create a link around some text). That function in turn calls a javascript function. Usually I would have put the javascript on the
10
2473
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 inside foo.js later in that same document by doing something like this: <script language="JavaScript" type="text/javascript">myfunction(myargs)
1
1434
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 are not available. They'd been working for over a year. The libraries are included in the <HEAD> of the HTML page: <script language="javascript" src="../inc/utils.js" type="text/javascript"></script>
3
4067
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, Shailesh
4
1580
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 discussed was: function object(o) { function F() {} F.prototype = o; return new F();
12
10893
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 other way of "getting at it" automatically. I'm not fussy about what language I use, be it JavaScript or something else. Anyone got any ideas? I've tried Exuberant Ctags, but that does not seem to work on very advanced scripts like Ext. I'm...
5
1177
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" style="width: 125px; height: 125px;" class="PopBoxImageSmall" onclick="Pop(this,50,'PopBoxImageLarge');" ondblclick="Revert
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
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 we have to send another system
3
2193
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.