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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.