Reputation: 104
in my .jsp file I have code like this (to the point)
<td width="200px">
<input type="text" id="${general.pk.code }_${MTPL[4].pk.run}"
name="${general.pk.code }_${MTPL[4].pk.run}"
value="${MTPL[4].value}" onChange="gg('${MTPL[4].jsCode }','${MTPL[4].pk.code }',this,'${MTPL[4].operator }','${MTPL[4].param1 }','${MTPL[4].param2 }','${MTPL[4].param3 }','${MTPL[4].param4 }','${MTPL[4].param5 }','${MTPL[4].pk.run }','${MTPL[4].param6 }','${MTPL[4].param7 }')"
style="text-align: right;">
</td>
<c:forEach items="${valueRun }" var="generalR">
<td width="200px">
<input type="text" id="${general.pk.code }_${generalR}"
name="${general.pk.code }_${generalR}"
value="" onChange="gg('${MTPL[4].jsCode }','${MTPL[4].pk.code }',this,'${MTPL[4].operator }','${MTPL[4].param1 }','${MTPL[4].param2 }','${MTPL[4].param3 }','${MTPL[4].param4 }','${MTPL[4].param5 }','${MTPL[4].pk.run }','${MTPL[4].param6 }','${MTPL[4].param7 }')"
style="text-align: right;">
</td>
</c:forEach>
when page finish load, the value be like this (inspect element)
input type="text" id="MTPL_4" name="MTPL_4" value="1100" onchange="gg('COPAS','MTPL_4',this,'','this','','4','','','4','','MTPL')" style="text-align: right;">
I want to get parameter on function gg() at javascript document ready. How to do that.
<script>
$(document).ready(function() {
var a = $("#MTPL_4").val(param1); //didnt get param1 value
});
</script>
I try .val()
but its only get value (1100). How get value inside onchange function gg();
(try to get "COPAS",'MTPL_4', etc)
Upvotes: 1
Views: 1063
Reputation: 350
You can use jquery attr method for this and then get substring out of it like below:
$(document).ready(function(){
var len = $("#MTPL_4").attr("onchange").length;
alert($("#MTPL_4").attr("onchange").substring(3, len-1));
})
Further if you want to split the string and get individual parameter which is separated by "," you can use split method.
Upvotes: 1