Selecting/Highlighting Rows AND Changing Value of

2019-09-05 21:07发布

This is a continuation on the project from before, seen here (Selecting/Highlighting Rows AND Changing Value of Highlighted Text Field in the Same Row). User Scription has been incredibly helpful. Thank you!

The next line of business to get this working the way I need it to work is to have it so that the fourth option in the menu is editable via onClick, but in a way that is different from the options above it, as it requires a different set of options. The options for this line involve changing the text only, and does not involve numbers in any way. I have figured out how to change the text via onClick from another thread on stackoverflow, but I need to now integrate this into my existing design. I've got the Plunker going (link below). As you can see, I can get the fourth option row's text to change no problem by using the little button that I put down below the wrapper for testing purposes. I need this one to be able to be adjust ONLY when it is highlighted, and with the existing D-pad left/right arrows — the same way the other lines do. Obviously, the values need to increase and decrease according to which button is pressed, too. The text phrases start at one place and end in another, so the onClick events need to cycle through them in sequence.

To further complicate or add to the project, I need to be able to have the user scroll down to the "more↓" option and then into a completely new set/window of options. I would imagine we would use something along the lines of CSS overflow: property, but when combining it with all of this code I'm not really sure how to pull that off.

As always, any help is appreciated!

Plunk it here: http://plnkr.co/edit/LarWS7qNrl0zXbRNaPS0?p=preview

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<head>
<title></title>

<style type="text/css">

/* Colors for later: 6acff6 6799ea cyan */


body {
font-family: arial, helvetica, sans-serif;
font-size: 1.7em;
}

#wrapper {
width: 800px;
height: 400px;
padding: 10px;
border: 1px solid #474747;
}

#screen-container {
float: left;
background: #6acff6;
width: 485px;
height: 300px;
border: 3px solid #efefef;
border-radius: 15px;
color: #ffffff;
overflow: hidden;
}

#screen-container h1 {
margin: 15px 0 0 0;
text-align: center;
text-transform: uppercase;
font-size: 1em;
font-weight: 100;
}

#d-pad {
position: relative;
float: right;
width: 300px;
height: 300px;
border: 3px solid #efefef;
border-radius: 15px;
}

ul {
margin: 5px 10px 0 -35px;
text-transform: uppercase;
}

li {
list-style-type: none;
line-height: 50px;
padding: 0 10px 0 10px;
}

li:selected {
color: #000;
}

.number-input {
float: right;
width: 50px;
height: 40px;
font-size: 1em;
text-align: right;
color: #ffffff;
background-color: transparent;
border: 0px;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}

#up {
position: absolute;
margin: 5px 0 0 0;
left: 120px;
width: 50px;
height: 50px;
background-color: #efefef;
cursor: n-resize;
}

#up, #down, #left, #right {
text-align: center;
font-size: .65em;
}

#down {
position: absolute;
margin: 0 0 5px 0;
bottom: 0;
left: 120px;
width: 50px;
height: 50px;
background-color: #efefef;
cursor: s-resize;
}

#left {
position: absolute;
left: 0px;
top: 110px;
width: 50px;
height: 50px;
margin: 5px;
background-color: #b7d9ef;
cursor: w-resize;
}

#right {
position: absolute;
right: 0px;
top: 110px;
width: 50px;
height: 50px;
margin: 5px;
background-color: #b7d9ef;
cursor: e-resize;
}

a {
display: block;
height: 100%;
width: 100%;
text-decoration: none;
}

</style>

<script type="text/javascript">
// For: http://www.codingforums.com/showthread.php?t=223429

var SBoxPtr = 0;
function SBoxPrevNext(amt) {
  var sel = document.getElementById('screen-container').getElementsByTagName('li');
  SBoxPtr += amt;
  if (SBoxPtr < 0) { SBoxPtr = 0; }
  if (SBoxPtr > sel.length-1) { SBoxPtr = sel.length-1; }
  for (var i=0; i<sel.length; i++) {
    if (i == SBoxPtr) { sel[i].style.backgroundColor = '0871b9'; }
                 else { sel[i].style.backgroundColor = '6acff6'; }
  }
}
document.onkeyup = changeChars;


function changeChars(e) {
  var KeyID = (window.event) ? event.keyCode : e.keyCode;   //  alert(KeyID);
  if (KeyID == 187) { SBoxPrevNext(1); }    // Key '+'
  if (KeyID == 189) { SBoxPrevNext(-1); }   // Key '-'
  if (KeyID == 40) { SBoxPrevNext(1); }     // Key 'DownArrow'
  if (KeyID == 38) { SBoxPrevNext(-1); }    // Key 'UpArrow'
}

window.onload=function(){
SBoxPrevNext(0)
 document.getElementById("up").onclick=function(){
   SBoxPrevNext(-1);
   };
 document.getElementById("down").onclick=function(){
   SBoxPrevNext(1);
   };
}

</script>

<script type="text/javascript">
function incrementValue()
{
    var value = parseInt(document.getElementById('number' + SBoxPtr).value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('number'+ SBoxPtr).value = value;
}
</script>

<script type="text/javascript">
function decrementValue()
{
    var value = parseInt(document.getElementById('number'+ SBoxPtr).value, 10);
    value = isNaN(value) ? 0 : value;
    value--;
    document.getElementById('number'+ SBoxPtr).value = value;
}
</script>


</head>
<body>

<div id="wrapper">

<div id="screen-container">
<h1>Program Menu</h1>
<ul>
<li>Program Number <input class="number-input" type="number" min="0" max="80" value="0" id="number0"></li>
<li>Etch Time Sec <input class="number-input" type="number" min="0" max="80" value="0" id="number1"></li>
<li>Etch Temp &#176;C <input class="number-input" type="number" min="20" max="100" value="20" id="number2"></li>
<li id="program-type">Pulse HNO3 <!--<input class="number-input" type="text" min="0" max="80" value="3&#58;1" id="number3">--></li>
<li style="text-align: right">more &#8595;</li>
</ul>
</div>

<div id="d-pad">
<div id="up"><p>&#9650</div><div id="down"><p>&#9660</div>
<div id="left" onclick="decrementValue()"><p>&#9668;</p></div><div id="right" onclick="incrementValue()"><p>&#9658;</div>
</div>


</div><!-- end wrapper -->


<script type="text/javascript">
var nextWord = (function() {
  var wordArray = ['Pulse Mix N:S 6:1','Pulse Mix N:S 5:1','Pulse Mix N:S 4:1','Pulse Mix N:S 3:1','Pulse Mix N:S 2:1','Pulse Mix N:S 1:1','Vortex HNO3','Vortex Mix N:S 6:1','Vortex Mix N:S 5:1','Vortex Mix N:S 4:1','Vortex Mix N:S 3:1','Vortex Mix N:S 2:1','Vortex Mix N:S 1:1','Pulse H2SO4','Pulse Mix S:N 1:1','Pulse Mix S:N 2:1','Pulse Mix S:N 3:1','Pulse Mix S:N 4:1','Pulse Mix S:N 5:1','Pulse Mix S:N 6:1'];
  var count = -1;
  return function() {
    return wordArray[++count % wordArray.length];
  }
}());

</script>


<button onclick="document.getElementById('program-type').innerHTML = nextWord();">&#9658;</button>


</body>
</html>

UPDATE 2013-09-27

I've updated my code and am getting close, but am stuck here: http://plnkr.co/edit/iZOJAx8BmKVMX8zII4kk?p=preview. I'm having a battle with that fourth row. It just doesn't quite work right. I can get the value to change and the proper text to display when I adjust the number with a keyboard, but it doesn't work with the onClick from the D-pad changes to the value. When the D-pad does it, no change to the text occurs. I think this has something to to with the "keyup" call in the code, but nothing I put in there (onBlur, onFocus, etc.) seems to work.

My current setup is far from elegant, so any suggestions on how to clean up that mess would be appreciated. I'm sure there's an easier way to accomplish the same thing, but this is what I conceived using the knowledge I have and the ideas that came to mind. Complete code can be seen below. Please pardon the relative links, as that was copied from my actual file (I'm starting to put together the interface now so I'm using graphics for many of the elements).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<head>
<title></title>

<link rel="stylesheet" type="text/css" href="font-collection.css">

<style type="text/css">

/* Colors for later: 6acff6 6799ea cyan */

body {
font-size: 1.7em;
background: #ffffff; /* Old browsers */
background: -moz-linear-gradient(top,  #ffffff 0%, #6393c1 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#6393c1)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #ffffff 0%,#6393c1 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #ffffff 0%,#6393c1 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #ffffff 0%,#6393c1 100%); /* IE10+ */
background: linear-gradient(to bottom,  #ffffff 0%,#6393c1 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#6393c1',GradientType=0 ); /* IE6-9 */
font-family: arial, helvetica, sans-serif;
padding: 10px;
}

h1 {
margin: 0 0 20px 20px;
font-size: 1.75em;
font-family: "alright-light","century gothic";
font-variant: small-caps;
font-weight: 100;
color: #427abd;
}

#wrapper {
width: 1150px;
height: 850px;
margin: 0 auto;
padding: 15px;
background-color: #fafafa;
border: 1px solid #474747;
border-radius: 10px;
}

#keypad-body {
margin: 0 auto;
width: 1082px;
height: 670px;
padding: 0px;
background-color: #b3b5b8;
border: 1px solid #474747;
border-radius: 10px;
}

#screen-container {
float: left;
margin: 90px 0 0 80px;
background: #6acff6;
width: 400px;
height: 220px;
border: 3px solid #d3d3d3;
border-radius: 15px;
color: #ffffff;
overflow: hidden;
}

#screen-container h1 {
margin: 15px 0 0 0;
text-align: center;
text-transform: uppercase;
font-size: 1em;
font-weight: 100;
font-family: arial, helvetica, sans-serif;
color: #ffffff;
}

#d-pad {
position: relative;
float: right;
margin: 80px 100px 0 0;
width: 432px;
height: 336px;
background-color: #b3b5b8;
border: 0px solid #d3d3d3;
}

ul {
margin: 5px 10px 0 -35px;
text-transform: uppercase;
font-size: .9em;
}

li {
list-style-type: none;
line-height: 32px;
padding: 0 10px 0 10px;
}

li:selected {
color: #000;
}

.number-input {
float: right;
width: 50px;
height: 30px;
font-size: 1em;
text-align: right;
color: #ffffff;
background-color: transparent;
border: 0px;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}

#up {
background: url(images/keypad-graphic-button-up.png);
background-repeat: no-repeat;
position: absolute;
margin: 30px 0 0 0;
left: 170px;
width: 90px;
height: 77px;
background-color: transparent;
cursor: n-resize;
}

#up, #down, #left, #right {
text-align: center;
font-size: .65em;
}

#down {
background: url(images/keypad-graphic-button-down.png);
background-repeat: no-repeat;
position: absolute;
margin: 0 0 30px 0;
bottom: 0;
left: 170px;
width: 90px;
height: 77px;
background-color: transparent;
cursor: s-resize;
}

#left {
background: url(images/keypad-graphic-button-minus.png);
background-repeat: no-repeat;
background-position: 10px;
position: absolute;
left: 30px;
top: 130px;
width: 62px;
height: 64px;
margin: 5px;
background-color: transparent;
cursor: w-resize;
}

#right {
background: url(images/keypad-graphic-button-plus.png);
background-repeat: no-repeat;
position: absolute;
right: 10px;
top: 130px;
width: 62px;
height: 64px;
margin: 5px;
background-color: #transparent;
cursor: e-resize;
}

#start {
background: url(images/keypad-graphic-button-start.png);
background-repeat: no-repeat;
position: absolute;
left: 133px;
top: 140px;
width: 181px;
height: 54px;
background-color: #transparent;
cursor: e-resize;
text-align: center;
}

#stop {
background: url(images/keypad-graphic-button-stop.png);
background-repeat: no-repeat;
position: relative;
float: right;
margin: 30px 100px 0 0;
width: 432px;
height: 66px;
border: 0px solid #d3d3d3;
background-color: transparent;
text-align: center;
}

#ntg-logo {
background: url(images/keypad-graphic-ntg-logo.png);
background-repeat: no-repeat;
margin: 25px auto;
width: 320px;
height: 116px;
}

#jetetch-pro-logo {
background: url(images/keypad-graphic-jetetch-pro-logo.png);
background-repeat: no-repeat;
margin: -70px 0 0 120px;
float: left;
width: 302px;
height: 151px;
}

#up, #down, #left, #right, #start, #stop {
border: 1px solid #000000;
}

a {
display: block;
height: 100%;
width: 100%;
text-decoration: none;
}

input.button {
font-family: trajan;
width: auto;
margin: 0px;
padding: 10px;
border: 0px;
color: #4378bd;
background-color: #efefef;
font-size: .75em;
text-transform: uppercase;
font-weight: 900;
}

input.button:hover {
color: #ffffff;
background-color: #858585;
}

.button {
width: auto;
padding: 5px;
border: 1px solid #4378bd;
border-radius: 5px;
font-size: .6em;
}

.clear {
clear: both;
}

</style>

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>

<script type="text/javascript">
// For: http://www.codingforums.com/showthread.php?t=223429

var SBoxPtr = 0;
function SBoxPrevNext(amt) {
  var sel = document.getElementById('screen-container').getElementsByTagName('li');
  SBoxPtr += amt;
  if (SBoxPtr < 0) { SBoxPtr = 0; }
  if (SBoxPtr > sel.length-1) { SBoxPtr = sel.length-1; }
  for (var i=0; i<sel.length; i++) {
    if (i == SBoxPtr) { sel[i].style.backgroundColor = '0871b9'; }
                 else { sel[i].style.backgroundColor = '6acff6'; }
  }
}
document.onkeyup = changeChars;


function changeChars(e) {
  var KeyID = (window.event) ? event.keyCode : e.keyCode;   //  alert(KeyID);
  if (KeyID == 187) { SBoxPrevNext(1); }    // Key '+'
  if (KeyID == 189) { SBoxPrevNext(-1); }   // Key '-'
  if (KeyID == 40) { SBoxPrevNext(1); }     // Key 'DownArrow'
  if (KeyID == 38) { SBoxPrevNext(-1); }    // Key 'UpArrow'
}

window.onload=function(){
SBoxPrevNext(0)
 document.getElementById("up").onclick=function(){
   SBoxPrevNext(-1);
   };
 document.getElementById("down").onclick=function(){
   SBoxPrevNext(1);
   };
}

</script>

<script type="text/javascript">
function incrementValue()
{
    var value = parseInt(document.getElementById('number' + SBoxPtr).value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('number'+ SBoxPtr).value = value;
}
</script>

<script type="text/javascript">
function decrementValue()
{
    var value = parseInt(document.getElementById('number'+ SBoxPtr).value, 10);
    value = isNaN(value) ? 0 : value;
    value--;
    document.getElementById('number'+ SBoxPtr).value = value;
}
</script>

</head>
<body>

<div id="wrapper">

<h1>Virtual Keypad</h1>

<div id="keypad-body">

<div id="screen-container">
<h1>Program Menu</h1>
<form method="post" id="keypad">
<ul>
<li>Program Number <input class="number-input" type="number" min="0" max="80" value="0" id="number0"></li>
<li>Etch Time Sec <input class="number-input" type="number" min="0" max="80" value="0" id="number1"></li>
<li>Etch Temp &#176;C <input class="number-input" type="number" min="20" max="100" value="20" id="number2"></li>
<li><input class="number-input program-type" type="text" min="0" max="80" value="1" id="number3">
<span class="text0">Pulse HNO3</span>
<span class="text1">Pulse HNO3</span>
<span class="text2">Pulse Mix N:S 6:1</span>
<span class="text3">Pulse Mix N:S 5:1</span>
<span class="text4">Pulse Mix N:S 4:1</span>
<span class="text5">Pulse Mix N:S 3:1</span>
<span class="text6">Pulse Mix N:S 2:1</span>
<span class="text7">Pulse Mix N:S 1:1</span>help</li>
<li style="text-align: right">more &#8595;</li>
</ul>
</div>

<div id="d-pad">
<div id="up"></div><div id="down"></div>
<div id="left" onclick="decrementValue()"></p></div><div id="start"></div><div id="right" onclick="incrementValue()"></div>
</div>
<div class="clear"></div>
<div id="stop"><a href="javascript:document.getElementById('keypad').reset();"></a></div>
<div id="jetetch-pro-logo"></div>
<div class="clear"></div>
<div id="ntg-logo"></div>

</div><!-- end keypad body -->

<center>
<br><br><form method="post">
<input class="button" type="button" value="Close Window"
onclick="window.close()">
</form>
</center>

</div><!-- end wrapper -->

<script type='text/javascript'>
//<![CDATA[ 
$(window).load(function(){
var span = $('.text0').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 0) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]>

//<![CDATA[ 
$(window).load(function(){
var span = $('.text1').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 1) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]>

//<![CDATA[ 
$(window).load(function(){
var span = $('.text2').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 2) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

//<![CDATA[ 
$(window).load(function(){
var span = $('.text3').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 3) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

//<![CDATA[ 
$(window).load(function(){
var span = $('.text4').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 4) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

//<![CDATA[ 
$(window).load(function(){
var span = $('.text5').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 5) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

//<![CDATA[ 
$(window).load(function(){
var span = $('.text6').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 6) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

//<![CDATA[ 
$(window).load(function(){
var span = $('.text7').hide();

$('.program-type').keyup(function() {

   var value = this.value;

   if (value == 7) {
       span.fadeIn();
   } else {
      span.fadeOut();   
   }

});

});//]]> 

</script>

</body>
</html>

1条回答
beautiful°
2楼-- · 2019-09-05 22:07

I finally understood what you mean. in order to achieve that you have to add to each of the input boxes a new attribute

  onfocus="DoSomething()"

So that final result would look like

<input onfocus="FocusStripe(0)" class="number-input" type="number" min="0" max="80" value="0" id="number0" ">

While the number 0 suite for the first box, the number 1 suite for the second box and so on.

Then we have to write a new function as follows:

function FocusStripe(stripeID) {
   var sel = document.getElementById('screen-container').getElementsByTagName('li');
   sel[stripeID].style.backgroundColor = '0871b9';
   sel[SBoxPtr].style.backgroundColor = '6acff6';
   SBoxPtr = stripeID;
}

I have created a working plnker example

I hope that answer your need. if this answer helped you please mark it as an helpful answer.

查看更多
登录 后发表回答