eva21 Posted August 11, 2008 Share Posted August 11, 2008 I have a select table in HTML...and when you click button up, it moves a text up. When you click down, it moves it down...here is the javascript: function moveup(){ var selObj = document.getElementById('quest'); var thisline = selObj.selectedIndex; var lineabove = thisline - 1; //alert('lineabove = ' + lineabove) if(thisline == 0) { alert('Sorry, you already have reached the top') } if(thisline >= 0){ selObj.value = selObj.options[lineabove].text; selText = selObj.options[thisline].text; selVal = selObj.options[thisline].value; upVal = selObj.options[lineabove].value; upText = selObj.options[lineabove].text; selObj.options[lineabove].text = selText; selObj.options[lineabove].value = selVal; selObj.options[thisline].value = upVal; selObj.options[thisline].text = upText; selObj.selectedIndex = lineabove; } // end if } // end of moveup function movedown(){ var selObj = document.getElementById('quest'); var thisline = selObj.selectedIndex; var lineabove = thisline + 1; //alert('lineabove = ' + lineabove) if (thisline > 3){ alert('Im sorry, you have reached the bottom') } if(thisline >= 0){ selObj.value = selObj.options[lineabove].text; selText = selObj.options[thisline].text; selVal = selObj.options[thisline].value; upVal = selObj.options[lineabove].value; upText = selObj.options[lineabove].text; selObj.options[lineabove].text = selText; selObj.options[lineabove].value = selVal; selObj.options[thisline].value = upVal; selObj.options[thisline].text = upText; selObj.selectedIndex = lineabove; } // end if However, my if statements: if (thisline > 3){ alert('Im sorry, you have reached the bottom') } Im trying to see if they are at the bottom, except i have hard coded it, and I do not want to do that. Is there an easier way to tell the user they are at the bottom of the table and can not move anymore? Link to comment https://forums.phpfreaks.com/topic/119157-javascript-coding-help/ Share on other sites More sharing options...
lemmin Posted August 11, 2008 Share Posted August 11, 2008 selObj.children.length should give you the number of items in the list and you can subtract one from it to get the last index. Link to comment https://forums.phpfreaks.com/topic/119157-javascript-coding-help/#findComment-613769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.