<title>Selector</title> <script> //i=0; mySelect = new Array(); function myfun(str) { color = document.getElementsByName(str).item(0).style.backgroundColor;"> <title>Selector</title> <script> //i=0; mySelect = new Array(); function myfun(str) { color = document.getElementsByName(str).item(0).style.backgroundColor;">

Selector Example In HTML

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Selector</title>
    <script>
        //i=0;
        mySelect = new Array();

        function myfun(str) {
            color = document.getElementsByName(str).item(0).style.backgroundColor;
            if (color == "red") {
                document.getElementsByName(str).item(0).style.backgroundColor = "";
                a = mySelect.indexOf(document.getElementsByName(str).item(0).value);
                //alert(a);
                mySelect[a] = "";
            } else {
                document.getElementsByName(str).item(0).style.backgroundColor = "red";
                //mySelect[i]=document.getElementsByName(str).item(0).value;
                mySelect.push(document.getElementsByName(str).item(0).value);
                //i++;
            }
        }

        function loadXMLDoc() {
            var xmlhttp;
            if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else { // code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "template1.1.php?mySelect=" + mySelect, true);
            xmlhttp.send();
        }
    </script>
</head>

<body>
    <div id="myDiv">
        <input type="button" name="b1" value="b1" onClick="myfun(this.name)"><br>
        <input type="button" name="b2" value="b2" onClick="myfun(this.name)"><br>
        <input type="button" name="b3" value="b3" onClick="myfun(this.name)"><br>
        <input type="button" name="b4" value="b4" onClick="myfun(this.name)"><br>
        <input type="button" name="Next" value="Next" onClick="loadXMLDoc()"><br>
    </div>
</body>

</html>


Leave a Reply