i have a page where i have multiple rows in a table and the no of rows is not fixed.
it is fetched using php loops from the database....each row has a drop down list containing 3 values....
i want a checkbox at some part of the page...only one....
which will enable me to change the selected element of all the drop down lists at once....
pls reply fast....
its urgent....
thnks in advance :D

If you have only drop down boxes (select elements in HTML terms) in your table, you can assign this function to the checkbox's onclick event:

function selectAll {
    // read all select elements
    var selectArray = document.getElementsByTagname('select');
    // loop thorugh the select elements array
    for(var oneSelect in selectArray) {
        // if you want i.e second option be selected, use index 1
        oneSelect.selectedIndex = 1;
    }
}

You can enhance this function by checking whether checkbox is in checked state or not. If you have other select elements on the page, you can use div or class. The above code has not been tested, it is just an idea.

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.