473,804 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JSP and Javascripts on same page (Passing values to JSP fromJavascript)

Hello.

I have a button on a form which goes to a function validate in
javascript as shown below:

<input type="button" name="<%= i%>" value="Edit"
onclick="valida te(this.name)">

The javascript:

<script language="javas cript">
var Action="";
function validate(Action ){
var actstring = Action.toString ();
ivalue = parseInt(actstr ing);
return confirm('Ok for this action : '+ivalue+' ?'); //this is to
test
}
</script>

I am changing the ivalue to an integer which eventually will access an
array built on the same page but using JSP. How can I pass the ivalue
back to the JSP?

Thank you.
Jun 27 '08 #1
3 6595
"Husain" <hu*******@gmai l.com>
I am changing the ivalue to an integer which eventually will access an
array built on the same page but using JSP. How can I pass the ivalue
back to the JSP?
Not very elegant: store it (as a string) in an invisible element of the
document. JSP can read it there.
Tom
Jun 27 '08 #2
Husain wrote:
I have a button on a form which goes to a function validate in
javascript as shown below:

<input type="button" name="<%= i%>" value="Edit"
onclick="valida te(this.name)">

The javascript:

<script language="javas cript">
<script type="text/javascript">
var Action="";
function validate(Action ){
By good convention, only identifiers referring constructors and constants
should begin with a capital letter. You should know that one from Java.
var actstring = Action.toString ();
The type conversion is unnecessary as the value is a string value already.
ivalue = parseInt(actstr ing);
Should be:

ivalue = parseInt(actstr ing, 10);

But since you are setting the value and not the user, this conversion is
unnecessary as well, at least in this particular code snippet.
return confirm('Ok for this action : '+ivalue+' ?'); //this is to
test
}
</script>

I am changing the ivalue to an integer which eventually will access an
array built on the same page but using JSP. How can I pass the ivalue
back to the JSP?
Suppose you have

<form action="...">
...
<input type="hidden" name="formactio n" value="">
...
</form>

you could write something along

<form action="..." onsubmit="valid ate(this)">
<script type="text/javascript">
function validate(f)
{
var action = arguments.calle e.action;
f.action = action;
return window.confirm( "Ok for this action: ' + action);
}
</script>

<input type="submit" name="foo" value="Foo me!"
onclick="valida te.action = this.name;">
</form>

But, as I said before in <news:48******* *******@Pointed Ears.de>, you should use

<form action="handles _foo_and_bar_su bmits.jsp" ...>
...
<input type="submit" name="foo" value="Foo me!">
<input type="submit" name="bar" value="Bar me!">
</form>

instead, so that your application degrades gracefully. Since this is not
exactly a new problem, I suggest you read these articles I posted not long ago:

<news:47******* *******@Pointed Ears.de>
<news:47******* *******@Pointed Ears.de>
A request in advance: *Please trim your quotes to the necessary minimum.*
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #3
Tom de Neef wrote:
"Husain" <hu*******@gmai l.com>
>I am changing the ivalue to an integer which eventually will access an
array built on the same page but using JSP. How can I pass the ivalue
back to the JSP?

Not very elegant: store it (as a string) in an invisible element of the
document. JSP can read it there.
Not just any element, but <input type="hidden" ...in the form to be
submitted. Else JSP will _not_ get at the value.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2429
by: Kerberos | last post by:
When I deliver a page as text/html, the javascripts work, but if delivered as application/xhtml+xml, the javascripts don't work: function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0 if(window.screen)if(isCenter)if(isCenter=="true"){ var myLeft = (screen.width-myWidth)/2; var myTop = (screen.height-myHeight)/2; features+=(features!='')?',':''; features+=',left='+myLeft+',top='+myTop;
2
2386
by: sdvoranchik | last post by:
We have an application that contains links that run javascripts to create pages in a separate frame. When these links open an external site, it causes the javascripts to no longer function. When we modified the links that invoke the javascripts from: <a href=javascript: top.doSomething> text </a> To: <span onclick=javascript:top.doSomething> text </span> The javascripts worked properly. Any ideas on why this now works or other...
2
1793
by: LC's No-Spam Newsreading account | last post by:
I asked a couple of days ago about the following arrangement (simplified). I made some progress using netscape.security.PrivilegeManager.enablePrivilege but still have to ask some further help. 1) a frameset contains - a number of javascript functions in the head (they do something like top.frames.document.myform.elements.value = v - two frames UP and DOWN
4
2352
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript functions through onload=function() in the body tag or through window.onload=function name in a script, the host's advertising javascripts disrupt my javascripts that are supposed to run onload so that they do not run. I am not able to control the...
2
5109
by: and | last post by:
Hi I have been validating all day most things are cool but I cant get by this problem. One I have listed the script (JAVASCRIPT ) in all the right placesnot a prob but the validator insists on going through t findind < (less than) in the code. why is it going through the script the scripts been tagged correctly? Also in the body where the link to the script is there is a table givng
10
2825
by: Joseph S. | last post by:
Hi, How do I pass a string from one call to a php block to another call in the same page but from another form? Here's my full php code: I'm using two forms in the same page. A hidden field 'f' with values '1' and '2' are used to distinguish calls from one form from those from the
1
1503
by: somaskarthic | last post by:
Hi In my PHP page while viewing the page source , it shows all the javascript codings and php comments. I don't want these comments and javascripts visible . Is there any methods to hide the javascripts , php comments and html comments ? It is most urgent. Please post your replies. Thanks in advance somaskarthic
4
1822
by: januarynow | last post by:
Generally, my site contains javascripts (a couple of freebie counters plus some CPM (pay-per-impression) and CPC (pay-per-click) ads), from four different firms, but they are all suffering from the same problem: every day, they have a 90%+ failure rate, in detecting traffic. My server log keeps reporting that numerous people visit the site, but those javascript companies keep saying otherwise. I have reason to believe that the server log is...
0
4288
Dormilich
by: Dormilich | last post by:
Organize your Scripts what you should have: basic Javascript understanding a standard compliant browser additional goodies: Firefox with the Firebug plugin installed
0
9588
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
10589
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...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9161
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
7625
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
6857
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
5527
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
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

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.