This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to assign dynamic value in javascript?  RSS feed

 
Raghu Mylavarapu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am unable to know how to send a value to a java script function. I am retrieving that value from the database and displaying. Retrieving part is written in scriplet.

Below is my code snippet:

Javascript:


I would like to pass the value of num to this function.

While displaying I am using html table. I have written this function to be called onClick=view();

Please let me know, if you need any other information. Please help.

Thanks in advance.

Raghu.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the page controller, create a scoped variable that contains the value.

Then, on the page, use the EL to display the value of the scoped variable.

E.g. in the controller:

And in the JSP:
 
Raghu Mylavarapu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear Bibeault,

Below is my code snippet,

[code:java scriptlet in jsp page]

<% for(SearchViewVDO SearchViewVDO: ((SearchVIO)request.getAttribute("IO")).getBaseDOList()){%>

[code:html]

<td align="center" valign="top" class="gray_devider graytxt_pro"><%=num%></td>
<td align="center" valign="top" class="graytxt_pro"><a href="" rel="dropmenu1" class>Action</a></td>

[code:java scriptlet in jsp page]

<%}%>

Now when mouse over is done on Action it shows Print option on which I need to call a window.open function. To this Print option I need to send a number.

[code:html]

<div id="dropmenu1" class="dropmenudiv_in">
<table width="130" border="0" align="center" cellpadding="0" cellspacing="0">
<td align="center" valign="middle" id="print"><a href="#"><img src="/agencyportal/images/agencyportal/print_icon.jpg" alt="Print" border="0" /></a></td>
</table>
</div>

[code:javascript]
<script type="text/javascript">

function view(num) {
var temp=document.getElementsByTagName('print');
var policyNum=policynum;
alert(policyNum);
temp.onclick = window.open("http://localhost/crmlogs/getPath?num="+num,toolbar=1,resizable=1,scrollbars=1,height=640,width=700);
}

</script>

Now when the I get the data in IO there are many numbers. I need to send the number in the row which I click.

For example,

1 Print
2 Print
3 Print
4 Print

Now when I click on Print next to 2 it should send 2 to the function in javascript.

Please let me know, if this possible or can you please suggest some other method to do so.

Thanks in advance.

With Regards,

Raghu.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!