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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.