I have a page where I have 100 combo boxes.
I made this bookmarklet :

javascript:document.getElementById("hioooo").selectedIndex = 38;

It works but only for the first combo box, all the rest combobox remains unchanged although they also have the id="hioooo".
What should I do to change all the combobox selection to the 38th item ?

thanks in advance
Kazilotus

Recommended Answers

All 7 Replies

An id should be unique. Have a look at getElementsByClassName and use class instead.

I tried this :

javascript:document.getElementsByClassName('hioooo').selectedIndex = 38;

on this

<select name="mdocs[cat][0]" class="hioooo">
    <option value="mdocs-cat-7">1</option>
    <option value="mdocs-cat-22">2</option>
    .....
</select>

Doesn't work.
nothing changes :(

getElementsByClassName returns a list of elements. You need to loop through them and set the index on each element separately.

I'm pretty much a noob, can you please write the script how it should be ?

Member Avatar for diafol

Did I read that right? A 100 select boxes? Just coz you can doesn't mean that you should.

I'm pretty much a noob, can you please write the script how it should be

You will forever stay a noob if you go down this road.

Are you sure that the 100 box solution is the right one?

It's not like how it looks, I have to do this with 1000 more documents.
Just check out the screenshot : https://kaylesblog.com/we.png
I'm Uploading a 100 document at a time, I have to select the category 1 by 1, which is a very big pain in the neck, a javascript script that could do this for all at once would save a lot of time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.