You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Shobhana.S, ASDC Chennai" <sh...@msdc.hcltech.com> on 2004/03/15 10:27:29 UTC

help in java script

Hi !

I'm getting a problem when i use java script in my struts application.

My code runs as follows:

<SCRIPT >
funtion change(value)
 {
 alert(value);
}
</SCRIPT>

<BODY>
...
,,,
<% String value="hello";%>
<html:text size="20" property="userId"
onchange="javascript:find(<%=value%>)"/></TD>

the problem is the onchange event is not being called.

when i don't pass a scriplet variable the event gets called..say
onchange="javascript:find('hello'); it gets callled..

could anyone suggest me how to pass a dynamic value to javascript function
in struts?

Thank you.

Shobhana


RE: help in java script

Posted by Andrew Hill <an...@gridnode.com>.
Remember the JSP script is evaluated server side and its result is what is
rendered to the browser.
Only the resulting html is what is evaluated by the browser which knows
nothing of the original scriptlets.

To check this out just do 'view source' in your browser on the page so you
can see what is actually being rendered to the response and seen by the
browser!

% String value="hello";%>
<html:text size="20" property="userId"
onchange="javascript:find(<%=value%>)"/></TD>

Will cause (something like) this to be rendered:

<input type="text" size="20" name="userId"
onchange="javascript:find(hello)"/>

BTW: Should have spotted earlier the "javascript:" which also is not
wanted - you only use that for hrefs! Take that out you get:
<input type="text" size="20" name="userId" onchange="find(hello)"/>

As you can see you are trying to pass a javascript variable named hello to
your method.
Surely you want to pass a javascript string containing the text hello?
ie:
<input type="text" size="20" name="userId" onchange="find('hello')"/>

Hence my suggestion to add in the quotes.
And lose that "javascript:" prefix!
(And shove a semicolon on the end though I think its optional in this case!)

hth
Andrew

-----Original Message-----
From: Andreas Solarik [mailto:a.solarik@gesig.at]
Sent: Monday, 15 March 2004 17:57
To: 'Struts Users Mailing List'
Subject: AW: help in java script


Hi Andrew and Shobhana,

As far as I know, you cant mix static text and dynamic text within a JSP. If
I remember correctly, something like the following code should work.

<%
  String tempString="javascript:find(" + value + "\";";	// Not sure about
the semicolon...
%>

and then:

<html:text size="20" property="userId"
onchange="<%= tempString %>"/></TD>

I'll make sure to try the single quotes (') around the dynamic text some
time, cause it's really annoying to use the method im describing here.


Regards, Andreas

-----Ursprüngliche Nachricht-----
Von: Andrew Hill [mailto:andrew.david.hill@gridnode.com]
Gesendet: Montag, 15. M?rz 2004 10:30
An: Struts Users Mailing List
Betreff: RE: help in java script


Should not that be:

<html:text size="20" property="userId"
onchange="javascript:find('<%=value%>')"/></TD>

(note the ' around value)

-----Original Message-----
From: Shobhana.S, ASDC Chennai [mailto:shobhanas@msdc.hcltech.com]
Sent: Monday, 15 March 2004 17:27
To: Struts Users Mailing List
Subject: help in java script


Hi !

I'm getting a problem when i use java script in my struts application.

My code runs as follows:

<SCRIPT >
funtion change(value)
 {
 alert(value);
}
</SCRIPT>

<BODY>
...
,,,
<% String value="hello";%>
<html:text size="20" property="userId"
onchange="javascript:find(<%=value%>)"/></TD>

the problem is the onchange event is not being called.

when i don't pass a scriplet variable the event gets called..say
onchange="javascript:find('hello'); it gets callled..

could anyone suggest me how to pass a dynamic value to javascript function
in struts?

Thank you.

Shobhana



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


AW: help in java script

Posted by Andreas Solarik <a....@gesig.at>.
Hi Andrew and Shobhana,

As far as I know, you cant mix static text and dynamic text within a JSP. If
I remember correctly, something like the following code should work.

<%
  String tempString="javascript:find(" + value + "\";";	// Not sure about
the semicolon...
%>

and then:

<html:text size="20" property="userId"
onchange="<%= tempString %>"/></TD>

I'll make sure to try the single quotes (') around the dynamic text some
time, cause it's really annoying to use the method im describing here.


Regards, Andreas

-----Ursprüngliche Nachricht-----
Von: Andrew Hill [mailto:andrew.david.hill@gridnode.com]
Gesendet: Montag, 15. M?rz 2004 10:30
An: Struts Users Mailing List
Betreff: RE: help in java script


Should not that be:

<html:text size="20" property="userId"
onchange="javascript:find('<%=value%>')"/></TD>

(note the ' around value)

-----Original Message-----
From: Shobhana.S, ASDC Chennai [mailto:shobhanas@msdc.hcltech.com]
Sent: Monday, 15 March 2004 17:27
To: Struts Users Mailing List
Subject: help in java script


Hi !

I'm getting a problem when i use java script in my struts application.

My code runs as follows:

<SCRIPT >
funtion change(value)
 {
 alert(value);
}
</SCRIPT>

<BODY>
...
,,,
<% String value="hello";%>
<html:text size="20" property="userId"
onchange="javascript:find(<%=value%>)"/></TD>

the problem is the onchange event is not being called.

when i don't pass a scriplet variable the event gets called..say
onchange="javascript:find('hello'); it gets callled..

could anyone suggest me how to pass a dynamic value to javascript function
in struts?

Thank you.

Shobhana



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: help in java script

Posted by Andrew Hill <an...@gridnode.com>.
Should not that be:

<html:text size="20" property="userId"
onchange="javascript:find('<%=value%>')"/></TD>

(note the ' around value)

-----Original Message-----
From: Shobhana.S, ASDC Chennai [mailto:shobhanas@msdc.hcltech.com]
Sent: Monday, 15 March 2004 17:27
To: Struts Users Mailing List
Subject: help in java script


Hi !

I'm getting a problem when i use java script in my struts application.

My code runs as follows:

<SCRIPT >
funtion change(value)
 {
 alert(value);
}
</SCRIPT>

<BODY>
...
,,,
<% String value="hello";%>
<html:text size="20" property="userId"
onchange="javascript:find(<%=value%>)"/></TD>

the problem is the onchange event is not being called.

when i don't pass a scriplet variable the event gets called..say
onchange="javascript:find('hello'); it gets callled..

could anyone suggest me how to pass a dynamic value to javascript function
in struts?

Thank you.

Shobhana



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org