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

Home Posts Topics Members FAQ

Passing variable from javascript to servlet!!!

9 New Member
Hi all,
I have one doubt,
can we pass a variable from javascript to servlet???

In Brief,
i am getting some values in javascript through jsp and the same values i
want in servlet. Ya i know i can get this values in servlet by using request.getPara meter("");
But thise values are dynamically generated so i dont know how many values will be. so i am planning to put some array list so that i can forward this values to servlet.

but i can't get this array which is declared in javascript!! :( so any buddy can help me how to get this dynamically generated values in servlet!!!

Thanks in Advance!! :)
Nov 21 '08 #1
7 8885
r035198x
13,262 MVP
You would get an array (or values in a select) using request.getPara meterValues instead.
Nov 21 '08 #2
vinodsk101
9 New Member
Hi,

But if i declare a array in javascript how can i get that array in servlet???
Is there any way to declare array in javascript/html and same we can use in servlet??
Nov 21 '08 #3
r035198x
13,262 MVP
You could just set the values to a hidden checkbox on the form and submit that.
Nov 21 '08 #4
vinodsk101
9 New Member
Hi,
Actually i have a dynamic table, i have add button to table which will add the new row to table, i want all the table values in servlet for my further use.
i used hidden select box,and i am adding all values to hidden selectbox, but problem is that i am getting only fist value, but if i give more than 2 or 3 rows, i am not receiving all values in servlet.

But if i use hidden checkbox how can i put all values in single checkbox value??
Nov 21 '08 #5
r035198x
13,262 MVP
The hidden select box approach should work as well. Post the code you used to populate the select.
Nov 21 '08 #6
vinodsk101
9 New Member
Hi,
I used this code to populate the select box.

Expand|Select|Wrap|Line Numbers
  1. var k;
  2.     for(k=1; k<=lastRow; k++)
  3.     {
  4.          var newOption = new Option(); 
  5.          var x=document.getElementById('selRow'+ k).selectedIndex;
  6.     var y=document.getElementsByTagName("option");
  7.  
  8.     alert(y[x].text+" In for loop has the index of: "+y[x].index);         
  9.  
  10.     newOption.text = y[x].text;
  11.     newOption.value = y[x].text;
  12.     document.table.ListBox4.options[len2] = newOption;
  13.     len2=len2+1;
  14.  
  15.     }
But some of the values are not inserting propertly!!
Nov 21 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Line 6 (setting y) will cause problems because you're getting all the options in the document (which is increasing all the time in the loop). So put that statement outside the loop.
Nov 25 '08 #8

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

Similar topics

1
1457
by: Stefano | last post by:
Posted: Fri Jan 23, 2004 3:59 pm Post subject: Variable Javascript -------------------------------------------------------------------------------- Hi all, i have a problem with javascript variable. I have a script that sets a global variable and open a dialog, then when i push a button of this dialog and i read the variable, this variable
9
2174
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script type="text/javascript"> function radioenable(value) { document.forms.search.elements.value.disabled=false;
3
2265
by: Das | last post by:
Hi all, I'm writig an application that sends an http request to java servlet file. I have to pass an xml file to the servlet. How should I pass xml file to the file. When I try to access the url directly it shows me Forbidden You do not have permission to access /RequestListenerServlet on this server.
5
3548
by: Paul | last post by:
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition and have another control with focus after the page loads from a different condition. A gets set in the code aspx.vb file and the script might look something like, <script language="javascript"> function DoHighlight(a) { if a = 1 {...
3
5801
by: JJ | last post by:
I am using a handler (processImage.ashx) to display an image. The image is displayed according to parameters passed in the querystring. The handerl is called via some clientside javascript. I want to send an array of unknown length to the handler. I am not sure whether the querystring is the best place to do this. What's the best way to send an array held in the client side javascript to the handler? Thanks in advance, JJ
5
10308
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they may also open up new chat windows with other members (just not the same one). - Each chat page is opened with the member name as the window name. - When I log off from the web page, I would like all the chat windows to automatically close. I...
1
2799
by: santaji | last post by:
I want to keep mapping of some key value pairs in javascript for that i m using a map inside javascript and want to access this map at server side in servlet where I don't know the key and value so I want to know is there anything can be done to access this var in servlet like java map where i can get both keys and corresponding values also. var output={} output = value1; output = value2; output = value3;
1
3337
by: shabnaz | last post by:
i have a servlet page which reads a file and stores it in a string variable.i need to display the contents of the file in a text area which that servlet creates an html in response.. how am i to do this? pls anyone help me..
0
9579
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
10332
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
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
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...
0
6853
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
5521
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...
1
4299
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
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
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.