• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1347
  • Last Modified:

how to pass values from javascript to servlet without adding inthe URL

I am getting somevalues in the javascript function, now i want to send these values to servlet without putting these in the URL. since my values contain special characters, if i add it in the URL and send it to Servelt , getting errors. Can anybody help me on how to pass values from javascript to servlet without adding in theURL.
1 Solution
You should use post as your method.  
<form  method="post"    ...
kbb1Author Commented:
i am getting some values based on <td> id . there is no form here, so i cannt pass it by post method.
my code is something like

var checkedRow = document.getElementById(j);
                    var checkedCells = checkedRow.getElementsByTagName("td");
                         var title =checkedCells[1].innerText;
              var size=checkedCells[2].innerText;
          var maxlimit=checkedCells[3].innerText;

and i need to dispaly these values thorugh a servlet
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Gurvinder Pal SinghCommented:
insert these values to a hidden input
<input type='hidden' name='hidden1' id='hidden1'>

and fetch these values in the servlet by
Sathish David Kumar NArchitectCommented:
use hidden filed !!

set the value to the flied in java script

like this

now u can get the form flied values in ur servlet as ur other flied getting  !!
You didn't tell us what you want to occur after you submit values to the server.
Do you want to refresh the page ?
Do you want to go to another page ?
Do you want to stay on same page with no action ?  

> there is no form here  
You can hide the form by using CSS. You can also programmatically  submit it. Please look at example code below here.  

If you don't want any action, then you could use AJAX.  
                   form{display:none; }
                    function SubmitForm(){
                                document.myHiddenForm.param1.value = "1234";
      <button type="button" name="mybutton" onclick="SubmitForm();" >submitHiddenForm</button>
      <form name="myHiddenForm" method="post" action="parameters.jsp" >
      <input type="text" name="param1" />

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now