Reputation: 197
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 a 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;
}
</script>
<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">
<p>Address:</p>
<input type="text" name="address">
<p>Count:</p>
<input type="text" id="count" name="count">
<p id='err_count' class='error'></p>
<input type="hidden" name="username" value="${pageContext.request.userPrincipal.name}">
<br>
NameProduct:
<input type="text" id="nameProduct" name="nameProduct">
<input type="text" id="priceProduct" name="priceProduct">
<input type="submit" value="Make order">
</form>
</div>
<table border="2px">
<tr>
<th>Name</th>
<th>Price</th>
</tr>
<c:forEach items="${productList}" var="product" varStatus="status">
<tr>
<td> ${product.getProductName()}</td>
<input type="hidden" id="productName" name="productName" value=${product.getProductName()}>
<td>${product.getPrice()}</td>
<input type="hidden" id="productPrice" name="productPrice" value=${product.getPrice()}>
<td>
<button class="myButton" onclick="show('block')">Make Order</button>
</td>
</tr>
How can I pass to my popup window name and price chosen row? Early on I used window.open()
and it worked, but now I use div for creating the popup window.
Upvotes: 0
Views: 926
Reputation: 131
Create the popup window this way
var childWindow=window.open("windowUrl");
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.
childWindow.setterFunction(name,price,chosenRow);
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;
Upvotes: 1