This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Get GWT value in Javascript

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,

I am trying to learn GWT,and confuse how to get GWT textbox value in javascript.
Like i am rendering GWT textbox with Div tag
<div id="tBox"/>

User enter some value in the Textbox.
I want that value in javascript?
Can anyone give me someguide line?

Thank you
 
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You can use ensureDebugId method to set an id to it and then use that id in javascript to access that textbox
2. You know the parent's id is 'tBox' you can use DOM in javascript to get its child
3. Passing the textbox element in to native javascript function.
 
Jordan Josh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thank you for your Reply.Still i am not able to send value back to javascript.I tried with native method ,Here I am ataching code.


On Jsp I have added GWT textbox and button.


I wann text entered by user in the nameFieldContainer(which is GWT textbox) on the same Jsp Page in javascript.

 
salvin francis
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what i tried and it worked:




corresponding HTML:

 
Jordan Josh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey salvin Thank you for your kind reply.but instead of taking value in window i wann that in $doc there i am confuse.
I already done for window.value but how to get in Javascript.

Is there any way that i can get window.value inside script variable.

Like var s = window.value;
So instead of returning value in window i want it in doc?

Can you suggest some way.?
 
salvin francis
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent tried it yet.
is there any particular reason why you are not preferring to use the $wnd object ?
 
Jordan Josh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah,I wann that value in script variable so i can use that for validation on submit buttons onclick event.
 
salvin francis
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jaan bhavsar wrote:Yeah,I wann that value in script variable so i can use that for validation on submit buttons onclick event.



Yes, But isnt that precisely what my code has accomplished ?

Also you should probably do your validations in GWT itself rather than writing javascript code for it. After all thats what the technology is for !!

As a side note, I think the best way was using ensureDebugId, did you explore that option ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!