473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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="validate(this.name)">

The javascript:

<script language="javascript">
var Action="";
function validate(Action){
var actstring = Action.toString();
ivalue = parseInt(actstring);
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 6577
"Husain" <hu*******@gmail.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="validate(this.name)">

The javascript:

<script language="javascript">
<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(actstring);
Should be:

ivalue = parseInt(actstring, 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="formaction" value="">
...
</form>

you could write something along

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

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

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

<form action="handles_foo_and_bar_submits.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**************@PointedEars.de>
<news:47**************@PointedEars.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*******@gmail.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 bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #4

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

Similar topics

3
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,...
2
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...
2
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. ...
4
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...
2
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...
10
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...
1
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...
4
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...
0
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.