How to transfer data from the input, NOT in the form?

Is in the form of such an element "rating"
FWhZqbH.jpg

normal div with sugrcane, click - change the value of the rating.
get current value is not a problem, but as it is set to send all form fields?

I can only think of the following: create a hidden input and when you click on the asterisk to assign the current value of this input, but it is believed that there is a more elegant solution. How would you do?
July 9th 19 at 11:23
3 answers
July 9th 19 at 11:25
Solution
I can only think of the following: create a hidden input and when you click on the asterisk to assign the current value of this input, but it is believed that there is a more elegant solution. How would you do?
- this is the best way, especially if you want to send along with the form
July 9th 19 at 11:27
Solution
Can every star to set data-attribute with its value and click-through when a person chooses a rating to add this unique star class, which then reads the data value.
<div class="starContainer"> 
 <img src="star.svg" data-star="1">
 <img src="star.svg" data-star="2">
 <img src="star.svg" data-star="3" class="selected">
 <img src="star.svg" data-star="4">
 <img src="star.svg" data-star="5"> 
</div>

// jQuery
function getRank(){
 var rank = $('.starContainer').find('img.selected').data('star');
 return rank;
}
 var rank = getRank();
jQuery.ajax({
 type: "POST",
 url: handler.php, 
 data: {
 'value1': a,
 'value2': b,
 'rank': rank 
},
 success: function (result) {...}
 });
like I said, the value to is not a problem as it continue to pass? - earnestine commented on July 9th 19 at 11:30
: Edited the post.
Collect data and send to the handler using ajax. Where variables a,b the value of other forms inputof - Delia_Armstrong51 commented on July 9th 19 at 11:33
: jQuery.ajax says nothing? Well, then go to Google. - Haley0 commented on July 9th 19 at 11:36
: Thank you - earnestine commented on July 9th 19 at 11:39
July 9th 19 at 11:29
how to pass a value not seen.
the functionality of the sprockets I have implemented, thanks - earnestine commented on July 9th 19 at 11:32
if the value you need to pass along with the form, a hidden field is the best solution. About the plugin, there is a possibility to call a callback function after select the rating where it is possible to pass the selected value in a convenient way (ajax hidden input, etc) - Delia_Armstrong51 commented on July 9th 19 at 11:35

Find more questions by tags JavaScriptAJAX