|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
getElementById in VWP netbeans6.0From the other forums i came to know that getElementById is no longer working with woodstock components in netbenas6.0 as the components are rendered as dynamic script tag and not using traditional Html tags.
For example, a text field is rendered as <script type="text/javascript"> dojo.addOnLoad(function() {webui.suntheme.widget.common.replaceElement("form1:textField1", {"widgetType":"webui.suntheme.widget.textField","value":"","required":false,"disabled":false,"style":"position: absolute; left: 120px; top: 48px","visible":true,"valid":true,"size":20,"readOnly":false,"id":"textField1","autoValidate":false});}); </script> So, document.getElementById("form1:textField1") returns the "span" element not the input text field element. How can I get a reference to textField element?? Is there a way to do this using dojo or jason? I just simply need to use some basic java script on the text field. But i am not able to get a reference to it. Any help would be appreciated. |
|
|
Re: getElementById in VWP netbeans6.0dojo does the replacement in the body onLoad event handler. If your
script waits until that has completed then the "getElementById" will actually return the replaced text input element and not the span element. The trick is how to wait. From a past email from Dan Labreque: Both Dojo and Woodstock widgets are created during the window.onLoad event. This was a change that Dojo forced upon us when upgrading to Dojo .9, back for 4.1 build #14. On the plus side, it allows for progressive rendering of HTML. Although you're code may have used dojo.addOnLoad, there is no guarantee that your code will be invoked last. (Other code, including Woodstcok widgets also use this function.) I've found that it is safer to test if a widget exists before invoking APIs. (I see you have used similar code.) For example: <head> <script type="text/javascript"> function init() { var domNode = document.getElementById('form1:fc1'); if (domNode == null || typeof domNode.setChooseButton != "function") { return setTimeout('init();', 10); } domNode.setChooseButton('form1:button1'); } </script> </head> <body onLoad="init();"> Note that a similar example exists in the Woodstock release notes. jokyog1 wrote: > >From the other forums i came to know that getElementById is no longer working > with woodstock components in netbenas6.0 as the components are rendered as > dynamic script tag and not using traditional Html tags. > > For example, a text field is rendered as > > > <script type="text/javascript"> > dojo.addOnLoad(function() > {webui.suntheme.widget.common.replaceElement("form1:textField1", > {"widgetType":"webui.suntheme.widget.textField","value":"","required":false,"disabled":false,"style":"position: > absolute; left: 120px; top: > 48px","visible":true,"valid":true,"size":20,"readOnly":false,"id":"textField1","autoValidate":false});}); > </script> > > So, document.getElementById("form1:textField1") returns the "span" element > not the input text field element. > > How can I get a reference to textField element?? Is there a way to do this > using dojo or jason? I just simply need to use some basic java script on the > text field. But i am not able to get a reference to it. > > Any help would be appreciated. > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: getElementById in VWP netbeans6.0Thank you for your help. But, I got confused with setChooseButton etc. Following is my code. It has one TextBox and and one Button. A Button Click calls java script function Test that shows the text box value in alert box. How can I fit what you showed here? If possible, please help me understand this.
<webuijsf:head binding="#{Page2.head1}" id="head1"> <webuijsf:link binding="#{Page2.link1}" id="link1" url="/resources/stylesheet.css"/> <webuijsf:script type="text/javascript"> function test(){ var temp = document.getElementById("form1:textField1"); alert(temp.value); } </webuijsf:script> </webuijsf:head> <webuijsf:body binding="#{Page2.body1}" id="body1" style="-rave-layout: grid"> <webuijsf:form binding="#{Page2.form1}" id="form1"> <webuijsf:textField binding="#{Page2.textField1}" id="textField1" style="position: absolute; left: 120px; top: 48px"/> <webuijsf:button binding="#{Page2.button1}" id="button1" onClick="test();" style="position: absolute; left: 264px; top: 48px" text="Button"/> </webuijsf:form> </webuijsf:body> Thanks. |
|
|
Re: getElementById in VWP netbeans6.0Following is my modified code but it still returns undefined.
<webuijsf:head binding="#{Page2.head1}" id="head1"> <webuijsf:link binding="#{Page2.link1}" id="link1" url="/resources/stylesheet.css"/> <webuijsf:script type="text/javascript"> function test(){ var temp = document.getElementById("form1:textField1"); alert(temp.value); } function init() { var domNode = document.getElementById("form1:textField1"); if (domNode == null || domNode.value == "undefined") { return setTimeout('init();', 10); } } </webuijsf:script> </webuijsf:head> <webuijsf:body binding="#{Page2.body1}" id="body1" style="-rave-layout: grid" onLoad="init();"> <webuijsf:form binding="#{Page2.form1}" id="form1"> <webuijsf:textField binding="#{Page2.textField1}" id="textField1" style="position: absolute; left: 120px; top: 48px"/> <webuijsf:button binding="#{Page2.button1}" id="button1" onClick="test();" style="position: absolute; left: 264px; top: 48px" text="Button"/> </webuijsf:form> </webuijsf:body> Thanks. |
|
|
Re: getElementById in VWP netbeans6.0In your case, you don't need the init() method. It should work as such.
Did you try debug using firebug to see what is going on? Firbug gives you the view of final rendered code. This is what happens in the browser. Browser receives the data as <script type="text/javascript"> // DOJO onload code to dynamically replace the spans below <script type="text/javascript"> <span id="form1:textField1"> <span id="form1:button1"> After onload javascript in the body element is called, the spans are replaced with TextField and Button. Since you are clicking on the button after seeing the button and TextField, that means the spans are already replaced and should work like any other script. The problem Dan mentions is about javascript code executed before onload is called. That is javascript embeded in the HTML itself. In that case it should be executed with delay to make sure onLoad() executes first. - Winston http://blogs.sun.com/winston > Following is my modified code but it still returns undefined. > > <webuijsf:head binding="#{Page2.head1}" id="head1"> > <webuijsf:link binding="#{Page2.link1}" id="link1" > url="/resources/stylesheet.css"/> > <webuijsf:script type="text/javascript"> > > function test(){ > var temp = > document.getElementById("form1:textField1"); > alert(temp.value); > } > > function init() { > var domNode = > document.getElementById("form1:textField1"); > if (domNode == null || domNode.value == "undefined") { > return setTimeout('init();', 10); > } > > } > > </webuijsf:script> > </webuijsf:head> > <webuijsf:body binding="#{Page2.body1}" id="body1" > style="-rave-layout: grid" onLoad="init();"> > <webuijsf:form binding="#{Page2.form1}" id="form1"> > <webuijsf:textField binding="#{Page2.textField1}" > id="textField1" style="position: absolute; left: 120px; top: 48px"/> > <webuijsf:button binding="#{Page2.button1}" > id="button1" onClick="test();" > style="position: absolute; left: 264px; top: > 48px" text="Button"/> > </webuijsf:form> > </webuijsf:body> > > Thanks. > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: getElementById in VWP netbeans6.0Hi ,
we are Recently using Woodstock in our project and we got the Problem as you and prakash discussed in this Mailing Archieve. i.e., "In your case, you don't need the init() method. It should work as such. Did you try debug using firebug to see what is going on? Firbug gives you the view of final rendered code. This is what happens in the browser. Browser receives the data as <script type="text/javascript"> // DOJO onload code to dynamically replace the spans below <script type="text/javascript"> After onload javascript in the body element is called, the spans are replaced with TextField and Button. Since you are clicking on the button after seeing the button and TextField, that means the spans are already replaced and should work like any other script. The problem Dan mentions is about javascript code executed before onload is called. That is javascript embeded in the HTML itself. In that case it should be executed with delay to make sure onLoad() executes first. " And am also able to see the Components in FireBug but am not able to get those components in Javascript like jokyog1 . So please provide me some solution. Thanks |
| Free embeddable forum powered by Nabble | Forum Help |