Nastya Gorobets Nastya Gorobets - 2 years ago 122
Javascript Question

How pass data to popup window wich created used div

I have table in my page with name and price product. Near only row there is a button "Make order" . When I click it I get popup window . I must pass my name and price to this popup .

<script type="text/javascript">
function show(state){
document.getElementById('window').style.display = state;
document.getElementById('wrap').style.display = state;

<div onclick="show('none')" id="wrap"></div>

<!-- Popup Window -->
<div id="window">
<img class="close" onclick="show('none')" src="/images/close.png">
<form onsubmit="return checkForm(this)" action="/user/confirmOrder">
<input type="text" name="address">
<input type="text" id="count" name="count">
<p id='err_count' class='error'></p>

<input type="hidden" name="username" value="${}">
<input type="text" id="nameProduct" name="nameProduct">
<input type="text" id="priceProduct" name="priceProduct">
<input type="submit" value="Make order">

<table border="2px">
<c:forEach items="${productList}" var="product" varStatus="status">
<td> ${product.getProductName()}</td>
<input type="hidden" id="productName" name="productName" value=${product.getProductName()}>
<input type="hidden" id="productPrice" name="productPrice" value=${product.getPrice()}>
<button class="myButton" onclick="show('block')">Make Order</button>

How can I pass to my popup window name and price chooesen row ?
Early I used and it works but now I use div for create popup window . Help me, please

Answer Source

Create the popup window this way


You then either need to create a function in the child window that sets the name, price, and chosen row and then call that function this way in the parent window.


Or, you could create global variables (not recommended ) in the child window for name, price, and chosen row and then set them from the parent window like this

childWindow.Name =name;
childWindow.Price = price;
childWindow.chosenRow = chosenRow;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download