jeudi 29 septembre 2016

Jquery not passing checkbox values correctly

I am attempting to make interactive checkboxes for my site which display a pop up once you tick a certain value. I have it mostly working however it wont seem to pass the names of the checkboxes to my alert test. It will always display question1 no matter which checkbox I use.

<script async  src="http://ift.tt/13qgtmt"></script>
<script>


function HasChanged()
{
    if($('.common_question').is(":checked")) 
    {  
        alert($('.common_question').val());
    }
}

</script>
<div id="chkbox" style="width=75%">
<form method="post">
        <fieldset>
                <legend>Select your reason for contact from below.</legend>
                        <h2>Premium Accounts</h2>
                        <input type="checkbox" onchange="HasChanged()" class="common_question" name="questiontype" value="question1" />I want to purchase a premium account<br />
                        <div style="display:none" id="prem1">Answer is here </div>
                        <input type="checkbox" onchange="HasChanged()" class="common_question" name="questiontype" value="question2" />I want to cancel a premium account<br />
                        <input type="submit" value="Next" />
        </fieldset>
</form>    
</div>

I am stumped as where I am going wrong, I just want the alert to just display the correct checkbox that has been picked.




Aucun commentaire:

Enregistrer un commentaire