onchange force page submit

时间:2010-04-16 09:59:40

标签: java javascript tapestry

<form jwcid="@Form" listener="listener:updateStaff">


<select jwcid="staffselect@Select" multiple="ognl:false" validators="validators:required" onchange="this.form.submit()" listener="listener:updateStaff">
               <span jwcid="@For" source="ognl:hrStaff" value="ognl:currentHrStaff" index="ognl:currentHrStaffIndex">
                   <option class="text11" jwcid="@Option" selected="ognl:hrStaffSelection[currentHrStaffIndex]" label="ognl:currentHrStaff"/>
               </span>
           </select>


</form>

当选择框上的onchange时,将提交此表单并调用我的pageValidate(),然后调用upadteStaff()侦听器方法。我想知道,当这样的提交被解雇时,可以onchange =''传递一个标志('selectboxisfired'字符串),我能够在pagevalidate()'selectboxisfired'中捕获?这将允许我在pagevalidate内的逻辑指示由selectbox触发。

1 个答案:

答案 0 :(得分:1)

onchange="window.submitTrigger=this; this.form.submit();"

然后,您可以阅读验证例程中的window.submitTrigger变量,以确定触发提交的元素,例如

/* somewhere in pagevalidate() routine */
/* note here that I am assuming the html id of the selectbox is "staffselect"
   -> I'm not familiar with Tapestry so simply had to make the assumption
      that this is the correct id - if not, change the string you're searching
      for accordingly */
if (window.submitTrigger.id = "staffselect") {
  //do something here
}

值得注意的是,我认为以这种方式使用onchange是一种糟糕的风格,但是不了解Tapestry,我只是给你最简单的改变,我已经认为它将在那里工作......