By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

SELECT drop down list - SKIP

P: n/a
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.

Mar 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Mar 19, 12:54 pm, "magix" <m...@asia.comwrote:
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
}

Mar 19 '07 #2

P: n/a
On Mar 20, 5:27 am, scripts.cont...@gmail.com wrote:
On Mar 19, 12:54 pm, "magix" <m...@asia.comwrote:
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;
}
--
Rob

Mar 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.