users@woodstock.java.net

Re: getElementById in VWP netbeans6.0

From: Winston Prakash <Winston.Prakash_at_Sun.COM>
Date: Wed, 02 Jan 2008 10:29:18 -0800

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">

<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.
>