javascript - How to know if the 7th radio button is selected without knowing name or id -


i have product page dynamically creates item options. know if 7th option selected, wont know "name" or "id" of radio button because generated automatically.

function teasamplecheck() {  	if(document.form1.radio1[7].checked == true) {      alert("you have selected sample");  }      else {          // nothing          }      }  }  });

<!--start: radio-format--> <div class="radio-format" itemprop="offers" itemscope itemtype="http://schema.org/offer"> <input type="radio" name="[oname]" id="radio-[value]" value="[value]" onclick="teasamplecheck();validatevalues(document.add,1);updateprice();"  [selected]> [feature] <div class="clear"></div> </div> <!--end: radio-format--> 

so how @ set of radio buttons , know 7th 1 selected?

the use of jquery .eq() may way.

function teasamplecheck() {     if( $(".radio-format input").eq(6).prop("checked") ) {         alert("you have selected sample");     }     else {         // nothing     } } 

this .eq(6) because argument zero-based.

so... 7th input inside parent radio-format...
if have whole radio-format div repeated many times... :

function teasamplecheck() {     if( $(".radio-format").eq(6).children("input").prop("checked") ) {         alert("you have selected sample");     }     else {         // nothing     } } 

edit
see question in comments

to trigger alert if click has occured on 7th radio, have change condition:

function teasamplecheck(obj) {     if (( obj.value == $(".radio-format input").eq(6).val() ) && ( obj.checked )){         alert("you have selected sample");     }     else {         // nothing     } } 

or (if whole radio-format div repeated) :

function teasamplecheck(obj) {     if (( obj.value == $(".radio-format").eq(6).children("input").val() ) && ( obj.checked )){         alert("you have selected sample");     }     else {         // nothing     } } 

it compares value of obj passed onclick handler:

onclick="teasamplecheck(this); ... 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -