Jump to content

Javascript coding help!


eva21

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.