SELECT drop down list - SKIP

M

magix

I have an drop down list

let say:

<SELECT name="id" id="id" OnClick="Skip()">
<option value="0"></option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</SELECT>




I have a skip button (with the OnClick javascript function, whenever I click
skip, the drop down list will select the next Item of the current one.

Example:
- the current selected item is Item 2, when click Skip, it will select Item
3
- the current selected item is Item 3, when click Skip, it will select Item
4
- the current selected item is Item 4, when click Skip, it will select the
first one, which is Value 0

like a circle...

how to do that in javascript ?
<Script language="javascript">

function skip()
{

}
</script>

thanks.
 
S

scripts.contact

I have an drop down list
I have a skip button (with the OnClick javascript function, whenever I click
skip, the drop down list will select the next Item of the current one.


great. what is the question ?

like a circle...
how to do that in javascript ?

if you already have the function then why you are asking.

html-
<SELECT id="idSel">
<option value="0">Item 0</option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</SELECT><br>
<button onclick="Next()"> Select Next </button>

JavaScript-
function Next(){
var SelEct=document.getElementById("idSel")
var Curr=SelEct.selectedIndex
SelEct.selectedIndex=(Curr<(SelEct.options.length-1))?++Curr:0
}
 
R

RobG

I have an drop down list
I have a skip button (with the OnClick javascript function, whenever I click
skip, the drop down list will select the next Item of the current one. [...]
how to do that in javascript ?
[...]

JavaScript-
function Next(){
var SelEct=document.getElementById("idSel")
var Curr=SelEct.selectedIndex
SelEct.selectedIndex=(Curr<(SelEct.options.length-1))?++Curr:0

}

How about:

function nextOption(sel) {
var idx = sel.selectedIndex;
sel.selectedIndex = ++idx % sel.options.length;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top