You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sanjeev_dutt <sa...@infy.com> on 2002/04/15 14:31:31 UTC
Passing JavaScript variable to a Java Scriptlet on a JSP page
Hi,
I have this piece of code on my JSP:
<Script language = "javascript">
function fnGetStates()
{
country = document.searchAcctForm.cboAcctAddrCountry.value;
alert(country);
document.write('<% Hashtable states = new Hashtable(); %>');
document.write('<% states = Combo.getStates(country);%>');
document.write('<% Enumeration state = states.keys(); %>');
document.write('<% while (state.hasMoreElements()) { %>');
document.write('<% String statecode = (String)state.nextElement(); %>');
document.write('<% String sts = (String)states.get(statecode); %>');
document.write('<html:option value="<%= statecode %>"><%= sts %></html:option>');
document.write('<% } %>');
}
</Script>
The problem is that "alert" is able to show the value of country. But within the document.write, It is not able to get the value of "country". It throws the following error :
~:\citione\web\WEB-INF\_tmp_war_myserver_myserver_web\jsp_servlet\_jsp\_search\__searchacct.java:801: cannot resolve symbol
probably occurred due to an error in /jsp/search/searchacct.jsp line 197:
document.write('<% states = Combo.getStates(country);%>');
Could some one help ?
Thanks
Sanjeev
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Passing JavaScript variable to a Java Scriptlet on a JSP page
Posted by Nicolas De Loof <ni...@cgey.com>.
If I understand what you're tryin to do, you want your Javascript code to
write JSP scriptlet (?)
Javascript is executed on the client, instead JSP code is executed on the
server. So a scriptlet can dynamicaly generate javascript code, but the
oposite has no sense.
You cannot execute any JSP code AFTER the HTML page has been sent to the
user HTML client. You can programaticaly set the javascript content of your
page with JSP code
So, if you want your state-select list to be dependent of the contry select
you have to :
- send a request to the server so that JSP code can generate the correct
list in a new HTML page.
OR
- include a full-javascript support for this feature. (This javascript datas
could be set by JSP code)
I have this piece of code on my JSP:
<Script language = "javascript">
function fnGetStates()
{
country = document.searchAcctForm.cboAcctAddrCountry.value;
alert(country);
document.write('<% Hashtable states = new Hashtable(); %>');
document.write('<% states = Combo.getStates(country);%>');
document.write('<% Enumeration state = states.keys(); %>');
document.write('<% while (state.hasMoreElements()) { %>');
document.write('<% String statecode = (String)state.nextElement(); %>');
document.write('<% String sts = (String)states.get(statecode); %>');
document.write('<html:option value="<%= statecode %>"><%= sts
%></html:option>');
document.write('<% } %>');
}
</Script>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Passing JavaScript variable to a Java Scriptlet on a JSP page
Posted by James Mitchell <jm...@telocity.com>.
http://javascript.internet.com/forms/auto-drop-down.html
Have fun
JM
> -----Original Message-----
> From: sanjeev_dutt [mailto:sanjeev_dutt@infy.com]
> Sent: Monday, April 15, 2002 8:32 AM
> To: Struts Users Mailing List
> Subject: Passing JavaScript variable to a Java Scriptlet on a JSP page
>
>
> Hi,
>
> I have this piece of code on my JSP:
>
> <Script language = "javascript">
> function fnGetStates()
> {
> country = document.searchAcctForm.cboAcctAddrCountry.value;
> alert(country);
>
> document.write('<% Hashtable states = new Hashtable(); %>');
> document.write('<% states = Combo.getStates(country);%>');
> document.write('<% Enumeration state = states.keys(); %>');
> document.write('<% while (state.hasMoreElements()) { %>');
> document.write('<% String statecode = (String)state.nextElement(); %>');
> document.write('<% String sts = (String)states.get(statecode);
> %>');
> document.write('<html:option value="<%= statecode %>"><%= sts
> %></html:option>');
> document.write('<% } %>');
> }
> </Script>
>
>
> The problem is that "alert" is able to show the value of country.
> But within the document.write, It is not able to get the value
> of "country". It throws the following error :
>
> ~:\citione\web\WEB-INF\_tmp_war_myserver_myserver_web\jsp_servlet\
> _jsp\_search\__searchacct.java:801: cannot resolve symbol
> probably occurred due to an error in /jsp/search/searchacct.jsp line 197:
> document.write('<% states = Combo.getStates(country);%>');
> Could some one help ?
> Thanks
> Sanjeev
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Passing JavaScript variable to a Java Scriptlet on a JSP page
Posted by Oliver Reflé <o....@gmx.de>.
I don't know exactly why you want to do that ?
Why don't you use
<% Hashtable states = new Hashtable();
states = Combo.getStates(country);
....
%>
and then you use
Country: <%=country.toString()%>
You don't need to use this javascript stuff, cause the disadvantage
is that you execute this document.write stuff on the client side.
You first execute you java scriptlet, the transfer the date to the
client and there the javascript code is executed.
So it would be easier if you would only work with Java scriptlets or Tags
here
Oliver
-----Original Message-----
From: sanjeev_dutt [mailto:sanjeev_dutt@infy.com]
Sent: Monday, April 15, 2002 2:32 PM
To: Struts Users Mailing List
Subject: Passing JavaScript variable to a Java Scriptlet on a JSP page
Hi,
I have this piece of code on my JSP:
<Script language = "javascript">
function fnGetStates()
{
country = document.searchAcctForm.cboAcctAddrCountry.value;
alert(country);
document.write('<% Hashtable states = new Hashtable(); %>');
document.write('<% states = Combo.getStates(country);%>');
document.write('<% Enumeration state = states.keys(); %>');
document.write('<% while (state.hasMoreElements()) { %>');
document.write('<% String statecode = (String)state.nextElement(); %>');
document.write('<% String sts = (String)states.get(statecode); %>');
document.write('<html:option value="<%= statecode %>"><%= sts
%></html:option>');
document.write('<% } %>');
}
</Script>
The problem is that "alert" is able to show the value of country. But within
the document.write, It is not able to get the value of "country". It throws
the following error :
~:\citione\web\WEB-INF\_tmp_war_myserver_myserver_web\jsp_servlet\_jsp\_sear
ch\__searchacct.java:801: cannot resolve symbol
probably occurred due to an error in /jsp/search/searchacct.jsp line 197:
document.write('<% states = Combo.getStates(country);%>');
Could some one help ?
Thanks
Sanjeev
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>