jquery - javascript not working on struts html tag -


i have following codes in jsp page in struts2 project

<select id="amountselect">  <s:iterator value="ratecarddetailslist" status="liststatusamount">     <option value="<s:property value='#liststatusamount.index'/>"><s:property value="rechargeamount"/></option> </s:iterator> </select> 

and corresponding script

 $(document).ready(function() {     $("#amountselect").change(function(){         var v= $("#amountselect").val();         var r= "<s:property value='ratecarddetailslist["+ v +"].mobilerate'/>";         alert(r);     }); }); 

where ratecarddetailslist array of particular bean(object) contain variable mobilerate. i'm getting null @ position of 'r' whil alerting (alert(r);). on inspecting element following

 $(document).ready(function() {         $("#amountselect").change(function(){             var v= $("#amountselect").val();             var r= "";             alert(r);          });     }); 

instead of variable 'v' if direcly give index i'm getting value i.e

 var r= "<s:property value='ratecarddetailslist[1].mobilerate'/>";     alert(r); 

does gives value in alert. coud reason?

this wildly invalid jsp + javascript:

var r = "<s:property value='ratecarddetailslist["+ v +"].mobilerate'/>"; 

take step , think code executing.

jsp, e.g., custom tags (here <s:property> tag) evaluated on server side, before sent browser.

javascript executed on client side, after being rendered on server , sent client. here you're trying mix server side code (the tag) javascript code, string concatenation. won't come close working.

to work need render valid javascript on server side, or use ajax , js values dynamically, etc. it's common render js data structures (e.g., json), there many other options.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -