user3331535
user3331535

Reputation: 1257

Onload remove radio button value

How to remove a Radio button value on onload of page..here is the list of radio button so dynamically i have to remove this value <input type="radio" name=myradio value="Null">Null

<input type="radio" name=myradio value="Bill">one
<input type="radio" name=myradio value="Sale">two
<input type="radio" name=myradio value="Null">Null

Upvotes: 0

Views: 992

Answers (3)

Pugazh
Pugazh

Reputation: 9561

Below script will remove the radio button with value null.

$(document).ready(function(){
    $("input[type='radio'][name='myradio'][value='Null']").remove();
});

Upvotes: 0

alexP
alexP

Reputation: 3765

window.onload = function() {
    var myradios= document.getElementsByName('myradio'); //Get all myradio elements from document

    for (var i = 0; i < myradios.length; i++) { //Loop all myradio elements
        if (myradios[i].value == 'Null') { //If value of element == null
            myradios[i].parentNode.removeChild(myradios[i].nextSibling); //Removes the "Null"-Text
            myradios[i].parentNode.removeChild(myradios[i]); //Removes the radio button
        }
    }
}

JSfiddle DEMO

Upvotes: 1

user986959
user986959

Reputation: 630

You can try this- first make a Javascript function like:

<script>
    function remvalue()
        {
    document.getElementById('myradiobutton').value="";

    }
window.onload=remvalue;
</script>

And then assign the ID to the radio button:

<input type="radio" id=myradiobutton name=myradio value="Null">Null

Upvotes: 1

Related Questions