• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem passing value from javascript of a jsp page to servlet

 
David kio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, i'm doing my FYP, and facing the following problem.
below is my code for the javaScript


then inside the form

After click the checkbox, it will invoke the deleteAccount function in javascript and send the value to it.

I have test that the data can be pass to javascript using alert(ckId);. However the data can't be pass to this line in javascript:

document.form.action = "<%=contextPath%>/AccServlet?tranx=deleteAccount&empId=ckID

The 'ckId' at the end of the line suppose to get the value of ckId and pass to servlet. However the value of ckID din't pass to servlet
========================================================
Below is the code inside the servlet:



Example:
in javaScript:
document.form.action = "<%=contextPath%>/AccServlet?tranx=deleteAccount&empId=ckId"; // the value that ckId hold is Samuel

in servlet, it only get "ckId" but not "Samuel"

Please if there is any way i can solve the problem , or any suggestion? thanks...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think that the ? should be automatically replaced with anything?

In any case, just add a hidden input to the submitted form rather than trying to tack it onto the URL.
 
David kio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thks for reply me.
Sorry for unclear and confusing description above, actually i didn't mean that the '?' will automatically replaced by anything. I go re-edit my post now.
hidden input? sorry i haven't learn it before.. Would mind give me an example on using it? thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
Stefan Evans
Bartender
Posts: 1822
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why complicate things by adding a parameter to the url or fudging with a hidden field?
Why not put the value on the checkbox?
Trimming it down a bit:




 
David kio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but it cant work. the deleteAccount function in javascript seems cant work at all. Below is my code.


 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, it looks like I introduced a javascript syntax error into the script:



should be



(ie remove the offending semi-colon)
Maybe that will fix it... though I haven't tried it myself.


BTW: Saying "It doesn't work" isn't much help.
An error message or perceived outcome of exactly WHAT is going wrong helps a lot.

Also, stop with the scriptlets in a JSP, and get with JSTL.

 
David kio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.. i try already and still can't work. There's is no any respond when i click the checkbox. And there's no any error msg shown. I'm using eclipse with Jboss server.
Maybe i should try just click the check box then make another "delete" button to invoke the action.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!