Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Need Some Help Here

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Got to trouble you guys again. Currently I am trying to pass javascript variables to a servlet or a bean file. I understand that javascript is client based and servlets are server based. But I have read up that there are ways to pass it. Anyone can show some examples on it?

Thanks in advance

Regards
Yans
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only way to get a value from the client to the server is to submit a request, and send that value as a request parameter.

Most often that is done by clicking a link / submitting a form.

With a link, you construct the URL with the parameter dynamically:
eg


With submitting a form, you normally put a hidden field onto the page (<input type="hidden") and then submit the form.

A technique that is catching on is AJAX - where you make a javascript call to submit a request to the server without reloading the whole page.
It still does a request/response, but it makes the page feel faster.

There are a few ideas.
Hope that helps,
evnafets
 
Yans Tan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Thanks alot I think I roughly know how to do. I will try your method. If I face any problems can I pm you?

Thanks in advance!

Regards
Yans
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Add hidden fields to your form

2. Call a javascript function when the submit button is clicked (onClick event). this javascript function should populate the hidden fields with the javascript variable values.
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yans Tan:
If I face any problems can I pm you?



Questions and answers should appear in the forum so that all readers may benefit.
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please read this.
 
Yans Tan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok sorry about that I will post my questions here instead of pm.

Regards
Yans
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One can pass a Java Variable to Javascript variable but reverse Is not possible.

Try to Think some other Way
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by abhishek gowlikar:
One can pass a Java Variable to Javascript variable but reverse Is not possible.

Try to Think some other Way



How about as request parameters. But I got you what you meant by saying that.
 
I don't like that guy. The tiny ad agrees with me.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic