jason_kelly
09-20-2013, 04:05 PM
Hello,
I need your help,
How can the JavaScript coding below be modified such that the background color in the input box won't unshade when the [↓] is clicked to display the avaliable options. The only time that both elements (input/select) should unshade, is if the user removes focus from both elements entirely by clicking on some other element in the page.
Scratching my head with this one:
<script type="text/javascript">
var shade = "yellow"
var unshade = "white"
window.onload = function() {
var x = document.getElementsByTagName('INPUT')
for (var i = 0; i < x.length; i++) {
if (x[i].readOnly == false) {
if (x[i].id == "refdocs_input") {
x[i].onfocus = function() {
this.style.backgroundColor = shade
document.getElementById('refdocs_wrapper').style.backgroundColor = shade
document.getElementById('refdocs_select').style.backgroundColor = shade
}//end function
x[i].onblur = function() {
this.style.backgroundColor = unshade
document.getElementById('refdocs_wrapper').style.backgroundColor = unshade
document.getElementById('refdocs_select').style.backgroundColor = unshade
}//end function
}//end if
}//end if
}//end for
}
</script>
HTML MARKUP:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#refdocs_select {
left: expression(this.previousSibling.offsetLeft);
width: expression(this.previousSibling.offsetWidth);
clip: expression("rect(2px auto 20px " + (this.previousSibling.offsetWidth - 20) + "px)");
overflow: hidden;
position: absolute;
top: -1px;
font-size: 9pt;
font-family: Arial;
}
#refdocs_wrapper {
border: 1px solid rgb(128,128,128);
display: block;
position: relative;
width: 180px;
height: 20px;
}
#refdocs_input {
border: 0;
height: 18px;
width: 180px;
position: relative;
font-size: 9pt;
font-family: Arial;
padding: 2px;
}
</style>
</head>
<body>
<div id="refdocs_wrapper">
<input id="refdocs_input" type="text"><select id="refdocs_select">
<option value=""></option>
<option value="ABC">ABC</option>
<option value="DEF">DEF</option>
<option value="GHI">GHI</option>
<option value="JKL">JKL</option>
<option value="MNO">MNO</option>
</select>
</div>
</body>
</html>
I need your help,
How can the JavaScript coding below be modified such that the background color in the input box won't unshade when the [↓] is clicked to display the avaliable options. The only time that both elements (input/select) should unshade, is if the user removes focus from both elements entirely by clicking on some other element in the page.
Scratching my head with this one:
<script type="text/javascript">
var shade = "yellow"
var unshade = "white"
window.onload = function() {
var x = document.getElementsByTagName('INPUT')
for (var i = 0; i < x.length; i++) {
if (x[i].readOnly == false) {
if (x[i].id == "refdocs_input") {
x[i].onfocus = function() {
this.style.backgroundColor = shade
document.getElementById('refdocs_wrapper').style.backgroundColor = shade
document.getElementById('refdocs_select').style.backgroundColor = shade
}//end function
x[i].onblur = function() {
this.style.backgroundColor = unshade
document.getElementById('refdocs_wrapper').style.backgroundColor = unshade
document.getElementById('refdocs_select').style.backgroundColor = unshade
}//end function
}//end if
}//end if
}//end for
}
</script>
HTML MARKUP:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#refdocs_select {
left: expression(this.previousSibling.offsetLeft);
width: expression(this.previousSibling.offsetWidth);
clip: expression("rect(2px auto 20px " + (this.previousSibling.offsetWidth - 20) + "px)");
overflow: hidden;
position: absolute;
top: -1px;
font-size: 9pt;
font-family: Arial;
}
#refdocs_wrapper {
border: 1px solid rgb(128,128,128);
display: block;
position: relative;
width: 180px;
height: 20px;
}
#refdocs_input {
border: 0;
height: 18px;
width: 180px;
position: relative;
font-size: 9pt;
font-family: Arial;
padding: 2px;
}
</style>
</head>
<body>
<div id="refdocs_wrapper">
<input id="refdocs_input" type="text"><select id="refdocs_select">
<option value=""></option>
<option value="ABC">ABC</option>
<option value="DEF">DEF</option>
<option value="GHI">GHI</option>
<option value="JKL">JKL</option>
<option value="MNO">MNO</option>
</select>
</div>
</body>
</html>