struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anuradha S.Athreya" <anuradh...@world2web.com>
Subject RE: Passing variable to javascript function
Date Mon, 29 Aug 2005 10:49:04 GMT
Thanks , this was very informative.

Regards
Anuradha 

-----Original Message-----
From: Leon Rosenberg [mailto:struts_user@anotheria.net] 
Sent: Monday, August 29, 2005 4:09 PM
To: user@struts.apache.org
Subject: RE: Passing variable to javascript function

Unfortunately it's not so easy, because you can't use a tag as an attribute
to the tag.
<html:link action="deleteData" name="deleteDataParams" scope="page"
onclick="return validateDelete(<bean:write name="data"/>)" 

This can't work, because the attribute (onclick) will not be evaluated.

There could be two possible solutions. First, leave the html taglib and drop
back to normal <a href...

Second: store the variable value in a javascript variable:
<script>
 var myData = '<bean:write name="data"/>'; </script> <html:link
action="deleteData" name="deleteDataParams" scope="page"
onclick="return validateDelete(myData)" 

Of course this only works if you have the value of myData at page generating
time. If the value is changed by something the user does on page, like
checking a checkbox, i would store it in a hidden field in the form and read
per javascript in validateDelete(), like this:
				
for (var i=0;i < document.formname.elements.length;i++){
   var e = document.formname.elements[i];
   if (e.value == 'set' && e.checked==true){
	doSubmit=true;
	myData = e.value; 
   }
}

the above javascript is only an example how to iterate over form fields with
javascript, it has not the required functionality.

regards
Leon






On Mon, 2005-08-29 at 14:28 +0530, Anjishnu Bandyopadhyay wrote:
> Hi Anuradha,
> 
> 
> 
> I think this will work:
> 
> 
> 
> onclick="return validateDelete('<bean:write name="abc"/>')"
> 
> where "abc" is the java variable that you put in request/session.
> 
> 
> 
> With best regards,
> 
> Anjishnu.
> 
> 
> 
> -----Original Message-----
> From: Anuradha S.Athreya [mailto:anuradhasa@world2web.com]
> Sent: Monday, August 29, 2005 2:26 PM
> To: User@Struts. Apache. Org
> Subject: Passing variable to javascript function
> 
> 
> 
> 
> 
> I had posted this problem a few days back, but I couldn't find a 
> solution to
> 
> this.
> 
> So I'm posting this again, since I need to implemen this urgently.
> 
> 
> 
> > <script>
> 
> > function validateDelete()
> 
> > {
> 
> >          return confirm("Delete Data");    
> 
> > }
> 
> > </script>      
> 
> >
> 
> >
> 
> >          <html:link action="deleteData" name="deleteDataParams"
> scope="page"
> 
> > onclick="return validateDelete()" >
> 
> >                                              Delete Data
> 
> >                                  </html:link>
> 
> >
> 
> >          To the validateDelete() Javascript function, I want to pass 
> > a
> java
> 
> > variable. How do I do it?
> 
> >          Once I pass the variable, my javascript function has to be :
> 
> >
> 
> >                      <script>
> 
> > function validateDelete(data)
> 
> > {
> 
> >          return confirm("Delete Data"+data);        
> 
> > }
> 
> > </script>      
> 
> 
> 
> **************** CAUTION - Disclaimer ***************** This e-mail 
> contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the
use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you
are not to copy, disclose, or distribute this e-mail or its contents to any
other person and any such actions are unlawful. This e-mail may contain
viruses. Infosys has taken every reasonable precaution to minimize this
risk, but is not liable for any damage you may sustain as a result of any
virus in this e-mail. You should carry out your own virus checks before
opening the e-mail or attachment. Infosys reserves the right to monitor and
review the content of all messages sent to or from this e-mail address.
Messages sent to or from this e-mail address may be stored on the Infosys
e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***



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




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


Mime
View raw message