Onchange event in Struts2

让人想犯罪 __ 提交于 2020-02-04 11:03:06

问题


How to call action on onchange event with select option in struts2.

Here is my code and how can I integrate with On change event.

<s:select name="menuItem" list="menuItems" listKey="menuItemID"

listValue="menuItemName" headerValue="--MenuItems--"

cssClass="selectbox_bg2" id="select" />

Can anyone please provide an example..

Thanks,


回答1:


There is no difference in how you apply onchange or any other javascript event handler to struts tag as compared to regular HTML tags. Struts2 select Tag Ref

<s:select name="menuItem" list="menuItems" listKey="menuItemID"

listValue="menuItemName" headerValue="--MenuItems--"

cssClass="selectbox_bg2" id="select" onchange="handleChange(this.value)"/>

JavaScript

function handleChange(value){
  window.location="callMyAction?ValueToSubmit="+value; //or you can submit a form from here or make an ajax call
}

Or if you are using jquery then

$("#select").change(function(e){
    var value = $(this).val();
    //submit a form or make ajax call or use window.location
});


来源:https://stackoverflow.com/questions/12948226/onchange-event-in-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!