2

I need to take a data from a script and then to use it in a form.

So when I click on this span:'

<span class="star rate1"></span>

The value from the js should go in this post:

<input type="hidden" name="rate_product" id="rate_er" />

The js script:

$(".rate1").click(function() {
    var rate = document.getElementById("rate_er");
    rate = 1;
});

But something is not working. The post is empty. Can u guys help me to find out the problem and what I'm doing wrong? thank you

2 Answers 2

2

Replace this:

var rate = document.getElementById("rate_er");
rate = 1;

with:

$("#rate_er").val(1);
Sign up to request clarification or add additional context in comments.

Comments

0

You can't just do rate = 1

Your rate variable need to have .value appended to it in order for it to actually work.

$(".rate1").click(function() {
    var rate = document.getElementById("rate_er").value;
    rate = 1;
});

OR

$(".rate1").click(function() {
    var rate = document.getElementById("rate_er");
    rate.value = 1;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.