• 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

Servlets & javascript

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet which retrieves a string from the database. Can I pass that string to a javascript variable???
That variable is than sent to the client side to do further processing.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like this in your web page:
<SCRIPT LANGUAGE="Javascript">
var myJSstring = '<%= myJSPClass.getValue() %>';
var myJSnumber = <%= myOtherJSPClass.getValue() %>;
</SCRIPT>
[This message has been edited by Edgar Sanchez (edited October 22, 2000).]
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
One of the methods through which you can access java variables in JavaScript in servlets is through hidden variables.
After retreiving the string from the database, put it as a value for a hidden field using the foll. code :
out.println("<input type=hidden name=fieldname value='"+varname+"'>");
You can access the same in JavaScript for client side validations using document.formname.fieldname.value.
I have used the same in many of my servlets.
See if this helps your cause.
Bye.

------------------
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai,
u can take the value of the varialble directly into javascript
like
out.println(" function valchk(){ ");
out.println(" var sampval = " + mservval + " ; ");
.....
or u can directly check like
out.println(" if(document.myhtm.t1.value = '"+mservval+" ) { ");
.
i think this can solve ur problem much
all the best'
bye
mohan
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic