简体   繁体   中英

Javascript onclick not working on radio button

I have a problem with javascript. I have downloaded a rating star plugin , this one to be exact: http://www.fyneworks.com/jquery/star-rating/#tab-Testing

I have multiple things to rate on one page, so i thought i could use an onclick to send it to a function, that sends it to my database with ajax. The problem is, when a rating star is clicked nothing happens, ive tried it on a regular submit button and the function gets executed.

Here is the code :

            <script type="text/javascript">
               function postform(){                      
                           alert('Thing is clicked');
                       };                 
            </script>

And the star is actually a radio button:

<input name="adv1" type="radio" class="star {split:4}" value="0.50" onclick="postform()"/>

I can't see what is wrong with the code, because when i test it on a regular button like this :

 <input type="submit" value="testbutton" onclick="postform()"/>

It gives me the alert Thing is Clicked.

Somehow the star doesn't like the onclick stuff.. Ive tested it in IE, Chrome and FF, nothing ever happens

could someone help me out here?

Thanks alot!

Edit:

As requested by Lukas , i have this in my head :

<script type='text/javascript' src='jquery.min.js'></script>
<script src='jquery.MetaData.js' type="text/javascript"></script>
<script src='jquery.rating.js' type="text/javascript"></script>

That library is handling the onclick event of the radio button for you, so you cannot handle it by adding an attribute onclick to the input element.

According to their documentation you need to put some code like this in a script:

$('.auto-submit-star').rating({
    callback: function(value, link){
        alert(value);
    }
});

Then add the class auto-submit-star to the class list of your radio button:

<input name="adv1" type="radio" class="auto-submit-star {split:4}" value="0.50" onclick="postform()"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM