Whing Dela Cruz
asked on
Clear the input border line
Hi, Experts, I want to clear the red border line in every time I click the table. how to do it base on the code below?
<script>
$(function() {
$(document ).on("click","#myPersonnelView89 input.i86s",function(){
let tr = $(this).closest('tr');
let a = tr.find('input')[0].value;
let b = tr.find('input')[2].value;
let c = tr.find('input')[3].value;
tr.find('input')[1].style.borderColor = "red"
document.getElementById('P1').value = a;
document.getElementById('P2').value = b;
document.getElementById('P3').value = c;
});
});
</script>
ASKER
Hi, Julian, this is my table...
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<script src="http://code.jquery.com/jquery-3.3.1.js"></script>
<body>
<div>
<table id="myPersonnelView89">
<tr>
<th>Code</th>
</tr>
<tr>
<td><input type="text" class="i86s" value="100"></td>
</tr>
<tr>
<td><input type="text" class="i86s" value="101"></td>
</tr>
<tr>
<td><input type="text" class="i86s" value="102"></td>
</tr>
</table>
</div>
<script>
$(function() {
$(document ).on("click","#myPersonnelView89 input.i86s",function(){
let tr = $(this).closest('tr');
let a = tr.find('input')[0].value;
tr.find('input')[0].style.borderColor = "red"
});
});
</script>
</body>
</html>
you can try add:
$('input').removeAttr('style');
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<script src="http://code.jquery.com/jquery-3.3.1.js"></script>
<body>
<div>
<table id="myPersonnelView89">
<tr>
<th>Code</th>
</tr>
<tr>
<td><input type="text" class="i86s" value="100"></td>
</tr>
<tr>
<td><input type="text" class="i86s" value="101"></td>
</tr>
<tr>
<td><input type="text" class="i86s" value="102"></td>
</tr>
</table>
</div>
<script>
$(function() {
$(document ).on("click","#myPersonnelView89 input.i86s",function(){
let tr = $(this).closest('tr');
let a = tr.find('input')[0].value;
$('input').removeAttr('style');
tr.find('input')[0].style.borderColor = "red"
});
});
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, guys both solution are working very well. I just want to say, thank you to both of you..
You are welcome.
in addition, you may think better ways of handling scenarios, such as if an end user moving the focus by pressing the tab, etc, then your "red border" should move accordingly as well. just a suggestion.
If you are talking about undoing line 9
Open in new window
Can't you just doOpen in new window
This will set the border of ALL input's back to the inherited value