You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Barbara Post <ba...@ifrance.com> on 2002/09/11 17:53:51 UTC

issues with javascript

I know this is a bit offtopic but maybe it is due to cocoon ? I hope not ! I
posted in javascript newsgroup too... I admit that javascript is not
complicated but I often have troubles with it...

"I generate a page with xml and xsl :

At a moment I have an input field, let's say "my_text", in "my_form" form
(no frames, one form in the body).

So I have a template that writes the html code for the input field and right
below the javascript tag to focus on it :

<script language="javascript">document.my_form.my_text.focus()</script>

IE 5.5 says that document.my_form.my_text is null or not an object.

At the moment the browser displays this javascript tag, the html generation
process hasn't produced the final </form> tag. May this be an issue ? Any
other ideas of what could be wrong ?"

Thanks,

Barbara


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


[SUMMARY] Re: issues with javascript

Posted by Barbara Post <ba...@ifrance.com>.
A colleague helped me to solve it out (form validator and set focus on first
erroneous input text). So this means that the javascript is surrounded with
<xsl:text/> and that the hack here is to use a javascript variable that
exists once a field is incorrect. My text inputs have complicated names you
see... like AAA_BBB.

Babs

 <!-- if error element -->
        <error when="error">
         <xsl:attribute name="name">
          <xsl:value-of select="../@Id"/>_<xsl:value-of
select="@Name"/></xsl:attribute>
         <font color="red">
          <xsl:value-of select="/page/errormessage">
         </font>
        </error>

        <input type="text" size="{$textfieldsize}" value="{$defaultvalue}">

         <xsl:attribute name="name">
          <xsl:value-of select="../@Id"/>_<xsl:value-of
select="@Name"/></xsl:attribute>
         <xsl:attribute name="id">
          <xsl:value-of select="../@Id"/>_<xsl:value-of
select="@Name"/></xsl:attribute>
        </input>
        <!-- set focus on first incorrect field -->
        <error when="error">
         <xsl:attribute name="name">
          <xsl:value-of select="../@Id"/>_<xsl:value-of
select="@Name"/></xsl:attribute>
         <!-- put here so the input is loaded first -->
         <script language="javascript">
          <xsl:text>if (error==null) document.form.</xsl:text>
          <xsl:value-of select="../@Id"/>
          <xsl:text>_</xsl:text>
          <xsl:value-of select="@Name"/>
          <xsl:text>.focus();</xsl:text>
          <xsl:text>var error=true;</xsl:text>
         </script>
        </error>

----- Original Message -----
From: "Stan Dyck" <sg...@standyck.com>
To: <co...@xml.apache.org>
Sent: Wednesday, September 11, 2002 6:01 PM
Subject: Re: issues with javascript


> Try rearranging the code so the the <script> element is written after the
> </form> tag. I suspect that the javascript interpreter cannot resolve
> "my_form" because it has not been completely written to the browser yet.
>
> hope this helps,
> StanD.
>
> ----- Original Message -----
> From: "Barbara Post" <ba...@ifrance.com>
> To: <co...@xml.apache.org>
> Sent: Wednesday, September 11, 2002 8:53 AM
> Subject: issues with javascript
>
>
> > I know this is a bit offtopic but maybe it is due to cocoon ? I hope not
!
> I
> > posted in javascript newsgroup too... I admit that javascript is not
> > complicated but I often have troubles with it...
> >
> > "I generate a page with xml and xsl :
> >
> > At a moment I have an input field, let's say "my_text", in "my_form"
form
> > (no frames, one form in the body).
> >
> > So I have a template that writes the html code for the input field and
> right
> > below the javascript tag to focus on it :
> >
> > <script language="javascript">document.my_form.my_text.focus()</script>
> >
> > IE 5.5 says that document.my_form.my_text is null or not an object.
> >
> > At the moment the browser displays this javascript tag, the html
> generation
> > process hasn't produced the final </form> tag. May this be an issue ?
Any
> > other ideas of what could be wrong ?"
> >
> > Thanks,
> >
> > Barbara
> >
> >
> > ---------------------------------------------------------------------
> > Please check that your question  has not already been answered in the
> > FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> >
> > To unsubscribe, e-mail:     <co...@xml.apache.org>
> > For additional commands, e-mail:   <co...@xml.apache.org>
> >
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: issues with javascript

Posted by Stan Dyck <sg...@standyck.com>.
Try rearranging the code so the the <script> element is written after the
</form> tag. I suspect that the javascript interpreter cannot resolve
"my_form" because it has not been completely written to the browser yet.

hope this helps,
StanD.

----- Original Message -----
From: "Barbara Post" <ba...@ifrance.com>
To: <co...@xml.apache.org>
Sent: Wednesday, September 11, 2002 8:53 AM
Subject: issues with javascript


> I know this is a bit offtopic but maybe it is due to cocoon ? I hope not !
I
> posted in javascript newsgroup too... I admit that javascript is not
> complicated but I often have troubles with it...
>
> "I generate a page with xml and xsl :
>
> At a moment I have an input field, let's say "my_text", in "my_form" form
> (no frames, one form in the body).
>
> So I have a template that writes the html code for the input field and
right
> below the javascript tag to focus on it :
>
> <script language="javascript">document.my_form.my_text.focus()</script>
>
> IE 5.5 says that document.my_form.my_text is null or not an object.
>
> At the moment the browser displays this javascript tag, the html
generation
> process hasn't produced the final </form> tag. May this be an issue ? Any
> other ideas of what could be wrong ?"
>
> Thanks,
>
> Barbara
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: issues with javascript

Posted by "Emmanuil Batsis (Manos)" <mb...@humanmarkup.org>.
Barbara Post wrote:
> Hi Manos and the others who replied :-)
> 
> The javascript code should be written only if I have an "error" tag for a
> specific text input field.
> 
> This error tag is produced by form validation. Then there is the classical
> code :
> 
> <!-- if error element -->
>         <error>
>          <xsl:attribute name="name">
>           <xsl:value-of select="../@Id"/>_<xsl:value-of
> select="@Name"/></xsl:attribute>
>          <xsl:attribute name="when">is-null</xsl:attribute>
>          <font color="red">
>           [explicit error message]
>          </font>
>          [and here I'd like to put my javascript but it fails executing]
>         </error>
> 
> you see that the name of the input field is determined "at xslt runtime"...
> and that the whole code above is in a template matching a certain tag, which
> .../@Id and @Name attributes are used... So I cannot use "onLoad" method...
> Any other ideas ?


Sorry Barbara, I don't really get it and have too much in my poor brain 
right now. Um, you can make the content of the function conditional in 
your XSLT; meaning, just produce an empty function or the field name you 
desire. The body just calls the function but what the function does is 
another story.

If you want to make the javascript *independent of the body tag*, just 
attach the function to the event in your javascript code instead:

<script language="javascript">
// this will trigger init when the document is loaded.
window.onload = init;

function init()
{
   document.getElementById('my_text').focus();
}
</script>

hth,

Manos




---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: issues with javascript

Posted by Barbara Post <ba...@ifrance.com>.
Hi Manos and the others who replied :-)

The javascript code should be written only if I have an "error" tag for a
specific text input field.

This error tag is produced by form validation. Then there is the classical
code :

<!-- if error element -->
        <error>
         <xsl:attribute name="name">
          <xsl:value-of select="../@Id"/>_<xsl:value-of
select="@Name"/></xsl:attribute>
         <xsl:attribute name="when">is-null</xsl:attribute>
         <font color="red">
          [explicit error message]
         </font>
         [and here I'd like to put my javascript but it fails executing]
        </error>

you see that the name of the input field is determined "at xslt runtime"...
and that the whole code above is in a template matching a certain tag, which
../@Id and @Name attributes are used... So I cannot use "onLoad" method...
Any other ideas ?

Thanks a lot,

Barbara

----- Original Message -----
From: "Emmanuil Batsis (Manos)" <mb...@humanmarkup.org>
To: <co...@xml.apache.org>
Sent: Thursday, September 12, 2002 9:57 AM
Subject: Re: issues with javascript


> Hi Barbara,
>
> Nothing to do with cocoon, but you are right; the document is not fully
> loaded and that's the problem. Try wrapping your code in a function and
> call it via the onload attribute of the body tag.
> BTW, you should be using DOM nowdays:
>
> <script language="javascript">
> function init()
> {
>    document.getElementById('my_text').focus();
> }
> </script>
> </head>
> <body onload="init()">
>
> Manos
>
>
> Barbara Post wrote:
> > I know this is a bit offtopic but maybe it is due to cocoon ? I hope not
! I
> > posted in javascript newsgroup too... I admit that javascript is not
> > complicated but I often have troubles with it...
> >
> > "I generate a page with xml and xsl :
> >
> > At a moment I have an input field, let's say "my_text", in "my_form"
form
> > (no frames, one form in the body).
> >
> > So I have a template that writes the html code for the input field and
right
> > below the javascript tag to focus on it :
> >
> > <script language="javascript">document.my_form.my_text.focus()</script>
> >
> > IE 5.5 says that document.my_form.my_text is null or not an object.
> >
> > At the moment the browser displays this javascript tag, the html
generation
> > process hasn't produced the final </form> tag. May this be an issue ?
Any
> > other ideas of what could be wrong ?"
> >
> > Thanks,
> >
> > Barbara
> >
> >
> > ---------------------------------------------------------------------
> > Please check that your question  has not already been answered in the
> > FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> >
> > To unsubscribe, e-mail:     <co...@xml.apache.org>
> > For additional commands, e-mail:   <co...@xml.apache.org>
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: issues with javascript

Posted by "Emmanuil Batsis (Manos)" <mb...@humanmarkup.org>.
Hi Barbara,

Nothing to do with cocoon, but you are right; the document is not fully 
loaded and that's the problem. Try wrapping your code in a function and 
call it via the onload attribute of the body tag.
BTW, you should be using DOM nowdays:

<script language="javascript">
function init()
{
   document.getElementById('my_text').focus();
}
</script>
</head>
<body onload="init()">

Manos


Barbara Post wrote:
> I know this is a bit offtopic but maybe it is due to cocoon ? I hope not ! I
> posted in javascript newsgroup too... I admit that javascript is not
> complicated but I often have troubles with it...
> 
> "I generate a page with xml and xsl :
> 
> At a moment I have an input field, let's say "my_text", in "my_form" form
> (no frames, one form in the body).
> 
> So I have a template that writes the html code for the input field and right
> below the javascript tag to focus on it :
> 
> <script language="javascript">document.my_form.my_text.focus()</script>
> 
> IE 5.5 says that document.my_form.my_text is null or not an object.
> 
> At the moment the browser displays this javascript tag, the html generation
> process hasn't produced the final </form> tag. May this be an issue ? Any
> other ideas of what could be wrong ?"
> 
> Thanks,
> 
> Barbara
> 
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
> 
> 
> 
> 



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>