button not work in IE11 - javascript

Problem:
http://jsfiddle.net/7ZDbB/1/
If I click the first and second row's deny button,
the third row's deny button can't click just in IE 11.
I tested on IE8、IE9、IE10、Firefox and Chrome, and not this problem.
This is source code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#main table{ border-collapse:collapse; width:100%; }
#main td{ border:1px solid #EEA; padding:4px 6px; }
#main table tr.excepted td{ background:#F99; }
form table {background:#FEFEF1}
</style>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body >
<div id="base">
<div id="main">
<form accept-charset="UTF-8" action="" method="post">
<input id="product_ids" name="product_ids" type="hidden">
<table>
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>product info</th>
</tr>
</thead>
<tbody>
<tr id="a_tr1_d_1084">
<td colspan="2">
<input type="button" value="allow" id="adAllowd_1084" style="display: none;">
<input type="button" value="deny" id="adExceptd_1084" onclick="onDenyBtnClicked('d_1084')">
</td>
<td>
<table>
<tbody>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
</tbody>
<tbody>
<tr>
<td>subheader1</td>
<td>subheader2</td>
<td rowspan="2">
other info
</td>
</tr>
<tr>
<td colspan="2">
image
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>product info</th>
</tr>
</thead>
<tbody>
<tr id="a_tr1_d_1085">
<td colspan="2">
<input type="button" value="allow" id="adAllowd_1085" style="display: none;">
<input type="button" value="deny" id="adExceptd_1085" onclick="onDenyBtnClicked('d_1085')">
</td>
<td>
<table>
<tbody>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
</tbody>
<tbody>
<tr>
<td>subheader1</td>
<td>subheader2</td>
<td rowspan="2">
other info
</td>
</tr>
<tr>
<td colspan="2">
image
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>product info</th>
</tr>
</thead>
<tbody>
<tr id="a_tr1_d_1090">
<td colspan="2">
<input type="button" value="allow" id="adAllowd_1090" style="display: none;">
<input type="button" value="deny" id="adExceptd_1090" onclick="onDenyBtnClicked('d_1090')">
</td>
<td>
<table>
<tbody>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
</tbody>
<tbody>
<tr>
<td>subheader1</td>
<td>subheader2</td>
<td rowspan="2">
other info
</td>
</tr>
<tr>
<td colspan="2">
image
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div id="allowAdSubmitButton"><input name="commit" type="submit" value="submit button"></div>
</form>
<script type="text/javascript">
var $j = jQuery;
function onDenyBtnClicked(adId) {
$j('#a_tr1_'+adId).addClass('excepted');
$j("#adAllow" + adId).show();
$j("#adExcept" + adId).hide();
$j("#product_ids").val(adId);
}
// -->
</script>
</div>
</div>
</body>
</html>
I solved this problem by adjust javascript code order,like this
$j('#a_tr1_'+adId).addClass('excepted');
$j("#adAllow" + adId).show();
$j("#adExcept" + adId).hide();
↓
$j("#adAllow" + adId).show();
$j("#adExcept" + adId).hide();
$j('#a_tr1_'+adId).addClass('excepted');
But I really don't know the reason, because I change any of follow 11 points , the problem can be solved.
delete table border-collapse style
#main table{ border-collapse:collapse; width:100%; }
delete td border style
#main td{ border:1px solid #EEA; padding:4px 6px; }
delete td background style
#main table tr.excepted td{ background:#F99; }
delete table backgroud style
form table {background:#FEFEF1}
delete submit button
delete javascript code that add 'excepted' css to tr
$j('#a_tr1_'+adId).addClass('excepted');
delete javascript code that show allow button and hide deny button
$j("#adAllow" + adId).show();
$j("#adExcept" + adId).hide();
delete javascript code that set value to 'product_ids'
$j("#product_ids").val(adId);
delete first colspan attribute on per row
delete first rowspan attribute on per row
delete second colspan attribute on per row
I'm quite puzzled and really don't get what is causing the problem. I'm hoping someone can help me, thank you.

This is an odd issue for sure. It appears to be a bad painting issue in IE 11 that prevents interacting with the page.
Take notice that after you click 2 deny buttons (order does not matter) the hover states of all the allow/deny buttons go away. Then click down and drag off of the submit button, and viola - all of the buttons (and text) are now interactive again.
Applying some best-practices to your code coincidentally fixes this issue as well. If you are using jQuery - you should not be using inline onclick attributes. A main goal of jQuery is to separate behavior from content. A better way to bind your click events would be to add a class to your deny and allow buttons then bind the click to them or to their closest static parent (in case your rows are being dynamically added). Also, since you're already toggling a class on the nearest parent, you may as well use that class to show/hide the correct button.
New JS:
$(function() {
$('#main').on('click', '.button-deny', function() {
$(this).closest('tr').addClass('excepted');
$("#product_ids").val($(this).data('ad-id'));
});
});
Additional CSS:
.excepted .button-deny,
.button-allow { display:none; }
.excepted .button-allow { display:inline-block; }
Relevant HTML Update:
<input type="button" value="allow" class="button-allow" data-ad-id="d_1084" />
<input type="button" value="deny" class="button-deny" data-ad-id="d_1084" />
And here's an updated fiddle - http://jsfiddle.net/7ZDbB/6/
If I can pinpoint the specific painting issue that is causing this issue, I'll update this answer.

Related

How to export same size images from html table to excel

I am facing some issues in exporting the image from html table. when I clicked on export button to download the html table as excel file. The downloaded xls file has different size of image. I want to export the images with the size as in the html table.
I am using following code, please give suitable suggestions regarding the problem. any other suggestion are also helpful.
<style>
table,th,td
{
border:2px solid red;
border-collapse:collapse;
}
</style>
</head>
<body>
<br/>
<br/>
<div id="divTable">
<center>
<table>
<caption>Person Information</caption>
<tr>
<th>Name</th>
<th>Gender</th>
<th>contact</th>
<th>Image</th>
</tr>
<tr>
<td rowspan="4"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3rlUFLRgsZ9kWB2DHyelOZdsRn6vXm2HlXKULG5qfYQZVYSrClw" alt="Flowers in Chania" width="80px" height="80px"></td>
<td >Male</td>
<td>7665716415</td>
<td>image</td>
</tr>
<tr>
<td >Male</td>
<td>7665716415</td>
<td>image</td>
</tr>
<tr>
<td >Male</td>
<td>7665716415</td>
<td><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS58D5NJFzmB2W_6tdzSVIJdHd8o_aACbV2Dh5AUHbODb62Q0r8Ew" alt="Abdevilliers" width="50px" height="50px"></td>
</tr>
<tr>
<td colspan="2">Male</td>
<td>image</td>
</tr>
</table>
</center>
</div>
<br/>
<br/>
<center>
<button id="myButton">Export Table data into Excel</button>
</center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$("#myButton").click(function() {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#divTable').html()));
});
</script>
</body>
</html>
Thanks in Advance.
I think you can try with percentage height and width instead of pixcel,
If in percentage your html view is not getting proper than You can show html in pixcel and when you are going to export it you will update to percentage.

How do I make an entire Table a button/link to another HTML page?

I have this table, that should be a button that link to another page. The reason is that the values of the table should be changeable with data from a database. The parameter can be changes to pH for example and the Value to 7 or something. But the table/button shall link to the same page. Where it is possible to set the Target.
So far this i what i got:
<table class="Button" >
<tr>
<td class="parameter"> Temperature</td>
</tr>
<tr>
<td class="Value">23&#x2103</td>
</tr>
<tr>
<td class="Target">Target: 30&#x2103 </td>
</tr>
</table>
So how do i make it a link/button?
You can use onclick and redirect your page.
Or wrap your table with <a>
<table class="Button" onclick="location.href='yourpage.html'" >
<tr>
<td class="parameter"> Temperature</td>
</tr>
<tr>
<td class="Value">23&#x2103</td>
</tr>
<tr>
<td class="Target">Target: 30&#x2103 </td>
</tr>
</table>
The same way as anything else.
You put an <a> element (with an href attribute) around it.
Wrap it into a link element:
<a href="LINK.html">
<table>
<tr>
<td class="parameter"> Temperature</td>
</tr>
<tr>
<td class="Value">23&#x2103</td>
</tr>
<tr>
<td class="Target">Target: 30&#x2103 </td>
</tr>
</table>
</a>
And if you wanna have a button, add a button element to that:
<button style="color:black; background-color:white; border-radius:5px;">
<a href="LINK.html">
<table>
<tr>
<td class="parameter"> Temperature</td>
</tr>
<tr>
<td class="Value">23&#x2103</td>
</tr>
<tr>
<td class="Target">Target: 30&#x2103 </td>
</tr>
</table>
</a>
</button>
You can do it using javascript onClick event or put <a> tag around it
Html
<table class="button" onClick="linkTo('https://www.google.com')">
.
.
.
</table>
Java Script
<script>
function linkTo(var link){
window.location = link;
}
</script>
Css for mouse point
<style>
table.button{
cursor: pointer;
}
</style>

Delete selected rows from HTML Tables

I am trying to delete selected rows (via checkbox) but I don't understand where I am going wrong
this is my code
JQuery
$("#delete").click(function(){
$("table input[type ='checkbox']:checked").parent().parent().remove();
});
HTML
<div class = "patientData">
<div class ="searchBar">
<input type = "search" name = "search" class = "search">
<i class ="fa fa-search"></i>
<button id = "delete">Delete Selected</button>
</div>
<table style ="width:95%" class = "Info">
<tr>
<th><input type="checkbox" id="select"> </th>
<th> Name</th>
<th>Number</th>
<th>Date</th>
</tr>
</table>
</div>
The user enters the rows which is why my table by default only has headings. I have stuck on this for a while now and no research is helping me solving the problem.
Please help if anyone can, Thanks in advance.
You should use the :has selector to get all rows containing a checked box, rather than working your way back up to the parent. This will keep the selector at the row-level, preventing DOM changes from accidentally working up too many parents and deleting large chunks of the page.
Something like:
$("#delete-button").on("click", function(e) {
$("#delete-table tr:has(td > input[type=checkbox]:checked)").remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="delete-button">Delete!</button>
<table id="delete-table">
<tr>
<th>
<input type="checkbox" />
</th>
<th>Header</th>
</tr>
<tr>
<td>
<input type="checkbox" />
</td>
<td>Row 1</td>
</tr>
<tr>
<td>
<input type="checkbox" />
</td>
<td>Row 2</td>
</tr>
<tr>
<td>
<input type="checkbox" />
</td>
<td>Row 3</td>
</tr>
</table>

jQuery .load duplicating div

I'm attempting to refresh a div and am ending up with a duplication of the div ie; one inside of the other. I'm currently using jQuery, Struts2, and the Struts2 jQuery plugin for my view.
what it is currently doing:
<div id="nameVolumeWrapper....>
<div id="nameVolumeWrapper....>
</div>
</div>
refresh script
<script>
function reloadContent() {
$('#nameVolumeWrapper').load('${jsonAction} #nameVolumeWrapper');
}
</script>
Element that calls the refresh script
<sj:select href="%{jsonURL}"
id="utility"
name="selectedUtility"
list="utilityList"
headerKey="-1"
headerValue="Please Select A Utility"
onchange="reloadContent()"
onChangeTopics="reloadSecondList"/>
div that I'm attempting to reload
<sj:div id="nameVolumeWrapper" listenTopics="reloadSecondList"
effect="pulsate" effectDuration="1000"
cssStyle="height:250px; overflow-y: scroll; width:910px;
margin-left:auto; margin-right:auto;">
<table id="pricingInput" class="footable" style="width: 800px;
table-layout: fixed; margin-left: auto; margin-right: auto;
margin-bottom:50px;">
<thead>
<tr>
<th style="text-align: center;">Account Name</th>
<th style="text-align: center;">Annual kWh Volume</th>
<th style="text-align: center">Rate Class</th>
<th style="text-align: center;">Add Another?</th>
</tr>
</thead>
<tbody>
<tr>
<td><s:textfield name="nameHolder" /></td>
<td><s:textfield name="volumeHolder" /></td>
<s:url id="jsonURL" action="jsonAction" namespace="/"/>
<td>
<sj:select href="%{jsonURL}"
id="rate_class" name="rateHolder"
list="rateClassList"
headerKey="-1"
headerValue="Please Select a RateClass"
reloadTopics="reloadSecondList"/>
</td>
<td>
<input type="button" class="addButton" value="Add" />
<input type="button" value="Delete" onclick="deleteRow(this)">
</td>
</tr>
</tbody>
</table>
long story short, how do I modify my javascript or div definition to make it so that the div doesn't duplicate when the javascript is called?
you could do something like this:
$.get("${jsonAction} #nameVolumeWrapper", function(data) {
$('#nameVolumeWrapper').html($(data).html());
});
Or if that doesn't work you could do:
var wrapper = $('#nameVolumeWrapper');
wrapper.load('${jsonAction} #nameVolumeWrapper', function() {
wrapper.children('#nameVolumeWrapper').unwrap();
});

How to keep outer table from resizing when inner table is shown/hidden

In a webpage, when a button is click, a table hidden is shown within another table. However, each time, when the hidden table is toggled, the width of the outside table would resize itself. The fiddle demo is here: http://jsfiddle.net/bEK8f/5/
I hope the initial width of the outer table would take into account of the size of the inner table. Therefore, the outer table width should not change by showing/hiding the inner table.
As cebirci showed below, fixing the width of the outer table and using the fixed layout would work. Note sure if the width of the outer table can be decided based on the hidden table. In this way, there is no need to manually set the outer table width.
Thank you very much!
I also include my code below:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#show").click(function(e){
e.preventDefault();
$('#cat1').toggle();
});
$("#calculate").click(function(e){
var diff = $('#diff').val();
var sd = $('#sd').val();
var effect = diff/sd;
$('#es').val(effect.toFixed(2));
$('#cat1').toggle();
});
});
</script>
<style>
table{border: 1px solid black;}
</style>
</head>
<body>
<table style="width:500px;table-layout: fixed;">
<tr class="row2">
<th class="col0">Effect size <button id="show">Show</button></th><td class="col1"><input type="text" id="es" value="0.1"></td>
</tr>
<tr class="cat1" id='cat1' style="display:none">
<th class="col0" id='test'></th>
<td class="col1">
<table>
<tr><th class="col0 centeralign" colspan="2"> Effect size calculation </th></tr>
<tr><td>Difference</td> <td> <input type="text" id="diff" value=".1"> </td></tr>
<tr><td>sd</td> <td> <input type="text" id="sd" value="1"> </td></tr>
<tr><td></td> <td> <button id="calculate">Calculate</button> </td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
You should use th tag for only header row of your table. In your table using td is better because you dont have any header row for titles etc..
In your html, your new table is appearing in a cell, and the cell is small for your table so it resizes. You can use colspan for merging two cells of your second row.
Your html code can be like that:
<table style="width:340px;table-layout: fixed;">
<tr class="row2">
<td class="col0">Effect size <button id="show">Show</button></td>
<td class="col1"><input type="text" id="es" value="0.1" /></td>
</tr>
<tr class="cat1" id='cat1' style="display:none">
<td class="col1" colspan="2">
<div style="display:inline"><table style="width:100%">
<tr><th class="col0 centeralign" colspan="2"> Effect size calculation </th></tr>
<tr><td>Difference</td> <td> <input type="text" id="diff" value=".1" /> </td></tr>
<tr><td>sd</td> <td> <input type="text" id="sd" value="1" /> </td></tr>
<tr><td></td> <td> <button id="calculate">Calculate</button> </td></tr>
</table></div>
</td>
</tr>
</table>
And jsfiddle link is http://jsfiddle.net/bEK8f/2/

Categories

Resources