Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Losing selection when using multiple rating components


Hi metronic staff

I'm using multiple rating components in 1 form

the issue I face is that when I select an option from the Rating Component 2 I lose the selection of the Rating Component 1

what should I do to preserve the check on Rating 1 component when checking an option of the Rating 2 component?

here is the code I'm using >>


<div id="rating_sel1" class="fv-row mb-10">
<label class="stepper-title" >Lorem ipsum dolor sit amet, consectetur adipiscing elit</label>
<div class="rating">
<input class="rating-input" name="rating1" value="0" checked type="radio" id="rating_1_opt0" />
<!--begin::Star 1-->
<div>
<a onclick="chkRating(1, 1)" id="rating_1_opt1_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">1
</a>
<input class="rating-input" name="rating1" value="1" type="radio" id="rating_1_opt1" />
</div>
<!--end::Star 1-->
<!--begin::Star 2-->
<div>
<a onclick="chkRating(1, 2)" id="rating_1_opt2_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >2</label>
</a>
<input class="rating-input" name="rating1" value="2" type="radio" id="rating_1_opt2" />
</div>
<!--end::Star 2-->
<!--begin::Star 3-->
<div>
<a onclick="chkRating(1, 3)" id="rating_1_opt3_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >3</label>
</a>
<input class="rating-input" name="rating1" value="3" type="radio" id="rating_1_opt3" />
</div>
<!--end::Star 3-->
<!--begin::Star 4-->
<div>
<a onclick="chkRating(1, 4)" id="rating_1_opt4_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >4</label>
</a>
<input class="rating-input" name="rating1" value="4" type="radio" id="rating_1_opt4" />
</div>
<!--end::Star 4-->
<!--begin::Star 5-->
<div>
<a onclick="chkRating(1, 5)" id="rating_1_opt5_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >5</label>
</a>
<input class="rating-input" name="rating1" value="5" type="radio" id="rating_1_opt5" />
</div>
<!--end::Star 5-->
</div>
</div>


<div id="rating_sel2" class="fv-row mb-10">
<label class="stepper-title" >Donec porttitor sed libero et semper. Nulla non iaculis augue</label>
<div class="rating">
<input class="rating-input" name="rating2" value="0" checked type="radio" id="rating_2_opt0" />
<!--begin::Star 1-->
<div>
<a onclick="chkRating(2, 1)" id="rating_2_opt1_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >1</label>
</a>
<input class="rating-input" name="rating2" value="1" type="radio" id="rating_2_opt1" />
</div>
<!--end::Star 1-->
<!--begin::Star 2-->
<div>
<a onclick="chkRating(2, 2)" id="rating_2_opt2_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >2</label>
</a>
<input class="rating-input" name="rating2" value="2" type="radio" id="rating_2_opt2" />
</div>
<!--end::Star 2-->
<!--begin::Star 3-->
<div>
<a onclick="chkRating(2, 3)" id="rating_2_opt3_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >3</label>
</a>
<input class="rating-input" name="rating2" value="3" type="radio" id="rating_2_opt3" />
</div>
<!--end::Star 3-->
<!--begin::Star 4-->
<div>
<a onclick="chkRating(2, 4)" id="rating_2_opt4_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >4</label>
</a>
<input class="rating-input" name="rating2" value="4" type="radio" id="rating_2_opt4" />
</div>
<!--end::Star 4-->
<!--begin::Star 5-->
<div>
<a onclick="chkRating(2, 5)" id="rating_2_opt5_btn" href="#" class="btn btn-light-warning font-weight-bold mr-2"
style="display: flex; align-items: center; justify-content: center;
width:20px; text-align: center; cursor:pointer;">
<label >5</label>
</a>
<input class="rating-input" name="rating2" value="5" type="radio" id="rating_2_opt5" />
</div>
<!--end::Star 5-->
</div>
</div>


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

Sorry for the late reply.

Please make sure you use different name attributes for each name component. Name of each rating component radio button should be unique.

Regards.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(