0

I'm trying to pass the value of a star rating using rateYo and the log gives me a:

4main.js:11 undefined

the way its set up, it uses the div to get a value. I'm trying to set the value for the star, and ultimately pass the value to route params. The backend PHP works, it's just a matter of passing the parameters.

Show.blade.php

<h5>Click to rate:</h5>

<form action="{{ route('rate', $book->id) }}" method="POST">
   {!! csrf_field() !!}
    <!-- <input id="rateYo" name="val" value="0" type="text"> -->
      <div id="rateYo" name="val"></div>
    <button type="submit" class="btn btn-primary">submit</button>
</form>

Main.js

$(document).ready(function() {
  'use strict'
  $('#rateYo').rateYo({
    starWidth: "40px"
  });

  $('#rateYo').click(function() {
    var owl = $('#rateYo').val();
    console.log(owl);

    $.ajax({
      type: 'POST',
      url: 'rate/' + owl,
      success: function(data) {
        // $("#msg").html(data.msg);
      }
    });
  });
});

Route

Route::post('rate/{book_id}','BookController@rate')->name('rate');
6
  • did you try var owl = $('#rateYo').text(); ? Commented Jul 24, 2018 at 6:17
  • let me try this out Commented Jul 24, 2018 at 6:21
  • still undefined Commented Jul 24, 2018 at 6:22
  • do you have value in rateYo div ? Commented Jul 24, 2018 at 6:22
  • 1
    I do not see any val() method defined in the docs. Have you tried this var owl = $('#rateYo').rateYo('rating');? It seems like thats te way? rateyo.fundoocode.ninja/#method-rating Commented Jul 24, 2018 at 8:08

1 Answer 1

1

See plugin documentation from http://rateyo.fundoocode.ninja/. You can not get rating value using val() function.

Try using

var rating = $rateYo.rateYo("rating");
console.log(rating)
Sign up to request clarification or add additional context in comments.

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.