简体   繁体   中英

how to pass parameter to a javascript function using struts taglib?

  1. I have a javascript function updateHiddenField(value) that gets a value as parameter and then sets this value as the value of a hidden field.

  2. I have a JavaBean flight with parameters id and flightNo .

Problem: How can I pass the parameter id of JavaBean flight to the js function updateHiddenField(value) when using <html:link> tag(struts)?

<html:link href="javascript:updateHiddenField(idToPassHere)"><bean:write name="flight" property="flightNo"/></html:link>

Thanks Umar

You don't seem to be gaining anything by using <html:link> over <a> - so that would be the easiest change:

<a href="javascript:updateHiddenField(<bean:write name="flight" property="id"/>)"> <bean:write name="flight" property="flightNo"/> </a>

More generally I would suggest you add event listeners to your DOM objects, rather than mixing markup & functionality.

<html:link href="javascript:updateHiddenField(<s:property value="id"/>)"><bean:write name="flight" property="flightNo"/></html:link>

假设您的taglib导入为<% @taglib prefix="s" uri="/struts-tags" %> taglib <% @taglib prefix="s" uri="/struts-tags" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM