I have a table in a jsp and want to create a pop up window when clicking on a table. Included is a jsfiddle with code and an attempt to connect javascript with a specific row but have not had success creating a pop-up.
This fiddle is an example - code I have currently includes a java for loop creating each tr with specific info from a database.
<tr OnClick="display('test');">
<td><strong>showSpeed</strong></td>
<td>15</td>
<td>The speed of the show/reveal</td>
</tr>
<script>function display(test) {
//display a pop up?
}</script>
/
Thank you.
I have a table in a jsp and want to create a pop up window when clicking on a table. Included is a jsfiddle with code and an attempt to connect javascript with a specific row but have not had success creating a pop-up.
This fiddle is an example - code I have currently includes a java for loop creating each tr with specific info from a database.
<tr OnClick="display('test');">
<td><strong>showSpeed</strong></td>
<td>15</td>
<td>The speed of the show/reveal</td>
</tr>
<script>function display(test) {
//display a pop up?
}</script>
https://jsfiddle/y2y1w24L/1/
Thank you.
Share Improve this question asked Mar 12, 2015 at 5:32 SlidetothewestSlidetothewest 351 gold badge1 silver badge5 bronze badges 3- You can use jqueryui./dialog/#modal-message for displaying JS dialog. – Sandeeproop Commented Mar 12, 2015 at 5:37
- 1 You're not having any success because there's nothing in the function. How can we help you fix it if you don't show your code? – Barmar Commented Mar 12, 2015 at 5:37
- possible duplicate of How to open JQuery UI popup onclick – RatDon Commented Mar 12, 2015 at 5:38
3 Answers
Reset to default 2You can use JQuery UI to display a nice popup. This code was made merging your code with the example found here: http://jqueryui./dialog/
<html xmlns="http://www.w3/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" href="//code.jquery./ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery./jquery-1.10.2.js"></script>
<script src="//code.jquery./ui/1.11.4/jquery-ui.js"></script>
<!--<link rel="stylesheet" href="/resources/demos/style.css">-->
</head>
<body>
<script>
function display(test) {
$("#dialog").dialog();
}
</script>
<table>
<tr onclick="display('test');">
<td><strong>showSpeed</strong></td>
<td>15</td>
<td>The speed of the show/reveal</td>
</tr>
</table>
<div id="dialog" title="Basic dialog" style="display:none">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
</html>
That's one option. You can also take a look at bootstrap modals found here: http://getbootstrap./javascript/#modals
Inside your function "display", event.target will give you a reference to whatever the user clicked:
function display(test) {
alert(event.target.outerHTML);
}
https://jsfiddle/y2y1w24L/2/
You should be able to use that to display the appropriate popup.
May this help you
var PopUP=document.createElement("div");
PopUP.className="PopUP";
PopUP.innerHTML="<div id='mainDivBack' style='display:block;'><div id='PopUpDiv' style='display:block;'>"+" Wele"+ "<input type='button' value='x' id='btnClose' style='display:block;' onclick='popClose();'/></div></div>";
document.body.appendChild(PopUP);
function popClose() {
document.getElementById("btnClose").style.display = 'none';
document.getElementById("PopUpDiv").style.display = 'none';
document.getElementById("mainDivBack").style.display = 'none';
}
function display(test) {
PopUP.innerHTML="<div id='mainDivBack' style='display:block;'><div id='PopUpDiv' style='display:block;'>"+test+ "<input type='button' value='x' id='btnClose' style='display:block;' onclick='popClose();'/></div></div>";
document.getElementById("btnClose").style.display = 'block';
document.getElementById("PopUpDiv").style.display = 'block';
document.getElementById("mainDivBack").style.display = 'block';
}
and CSS for this #btnClose { background: none repeat scroll 0 0 #dd2904; border: 1px solid #c13031; color: white; font-size: 18px; font-weight: bold; margin: 5px; padding: 0 1px 4px; position: absolute; right: 10px; top: 0; } #btnClose:hover { background: none repeat scroll 0 0 #ff4565;
}
#PopUpDiv
{
background: none repeat scroll 0 0 lightgray;
border: 1px solid gray;
border-radius: 8px;
box-shadow: 1px 1px 12px 3px white;
font-family: "Lucida Console" ,arial;
height: 70px;
padding: 35px;
position: absolute;
width: 300px;
}
#mainDivBack
{
background: radial-gradient(lightgray, transparent) repeat scroll 0 0 transparent;
height: 100%;
left: 0;
padding: 20% 25%;
position: fixed;
top: 0;
width: 100%;
}
.Grid
{
background-color: #fff;
border: 1px solid #525252;
border-collapse: collapse;
color: #474747;
float: left;
font-family: Calibri;
width: 99%;
}