开发者

selecting s:select value using javascript

I have an iterator in jsp and the iterator contains 2 lists:

<s:iterator value="reportNamesList">
     <s:select name="hour" listKey="codeDes开发者_JS百科c" listValue="code" list="hourList" />
     <s:select name="minute" listKey="codeDesc" listValue="code" list="minutesList" />
</s:iterator>

Now my requirement is that when hour value is selected (say as 10), the minute dropdown value should also become 10.

I am using javascript. Kindly suggest how to do it.


@Naved is correct; you interact with tag-produced DOM elements the same way as any other (although I'd use jQuery and save yourself a lot of time). You can explicitly set an id by using the id element.

In your case, since you'll have multiple groups of select boxes, you'll need to create the id based on something unique in the reportNamesList, perhaps an id. Your id attribute, then, would probably look something like id="hours_%{id} or if you use the <s:iterator>'s var attribute, id=hours_%{#foo.id}.

Your JavaScript would need to bind each hours select to its associated minutes select.


The code seems that you are coding it in Struts2. Although I am not very much aware of it but the simplest way I found to write any javascript for these types of framework is

  1. Run your code in browser and view the page source
  2. Locate the id or name given to your desired control (in your case it is select for hour). Say it selHour.
  3. Write the javascript code using getElementById('selHour') or getElementsByName('selHour') and do your stuff.

I hope this will help you to give the proper output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜