Javascript - If no radio buttons are selected, check the first one -


i'm beginner in javascript. have several radio buttons on dynamic page , want create script make following:

html:

    <input type="radio" id="elemainfoto">     <input type="radio" id="elemainfoto">     <input type="radio" id="elemainfoto"> 

javascript:

    var radio = '#elemainfoto',     if(radd.value == 0) {         radd.checked first radio element,     } else {         keep way is,     } 

if none of radio elements marked, mark first compulsory.

i expectation first item selected default, should use html , not javascript , please note should not use 2 html elements same id in case should either replace class and/or add unique ids elements.

<input type="radio" class="elemainfoto" id="item1" checked> <input type="radio" class="elemainfoto" id="item2"> <input type="radio" class="elemainfoto" id="item3> 

updated answer based on robg comment.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -