0

Hi there (I'm a complete JS newbie so please no bullying) I'm trying to pass formID inside my score variable but I don't think I'm getting my selector right, can anyone tell me what I'm doing wrong ?

Edit: Sorry everyone, I'm getting tired. My issue: I cannot properly select the value of my score var.

JS

function addScore(formId) {
var show_id = $('#show_id-'+formId).val();  
var user_id = $('#user_id-'+formId).val();
var score = $('input[value="tvshowrating' + formID +'"]').val();

HTML

    <form id="40">
        <div class="your-score">
            <div class="">Your Score</div> <div id="flash"></div>
             <input class="hover-star" type="radio" name="tvshowrating40" value="1" title="1"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="2" title="2"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="3" title="3"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="4" title="4"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="5" title="5"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="6" title="6"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="7" title="7"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="8" title="8"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="9" title="9"  />
             <input class="hover-star" type="radio" name="tvshowrating40" value="10" title="10"  />
             <input type="hidden" id="show_id-40" value="40" /> 
             <input type="hidden" id="user_id-40" value="2" />
             <span id="hover-test" style="margin:0 0 0 20px;"></span>
             <input id="submitscore" type="submit" value="Submit scores!" onclick="addScore(40);" />  
        </div>
    </form>
</div>
CharlieAus
  • 83
  • 1
  • 7

2 Answers2

4

You probably want the checked value:

$('input[name="tvshowrating' + formID +'"]:checked').val()

Here is another question that answers your problem: Get Value of Radio button group or How can I know which radio button is selected via jQuery?

Community
  • 1
  • 1
Kru
  • 4,195
  • 24
  • 31
3

You're selecting <input>s by value.

You probably want input[name=....

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • The names dont need to be different, just use the ":checked" selector to find which radio button is selected – Ian May 10 '13 at 22:42