Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get GWT value in Javascript

 
Jordan Josh
Ranch Hand
Posts: 38
  • 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
 
salvin francis
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit 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: 38
  • 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: 1263
10
Eclipse IDE Google Web Toolkit 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: 38
  • 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: 1263
10
Eclipse IDE Google Web Toolkit 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: 38
  • 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: 1263
10
Eclipse IDE Google Web Toolkit 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 ?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic