lundi 21 décembre 2015

PHP submit an form only if checkbox checked

I have a form with a check box and an input text. Here is my form:

<form action="index.php?option=com_platiniumchristmas&view=success"  method="post">
 <label><input type="checkbox" name="termsConditions" id="chbx" value="Yes" onclick="foo()" /> <?php echo JText::_('COM_PLATINIUMCHRISTMAS_TERMSCONDITIONS_TEXT');?></label>            

        <input type="submit"value="Emitir Voucher" class="btn btn-success" style="float: right" />
            <div style="overflow: hidden; padding-right: .5em;">
            <input type="text" name="friendName" style="width: 100%;" />

            <input type="hidden" name="canal" value="<?php echo $_POST["canal"]; ?>"/>

            </div>​
    </form>

The idea is only to submit the form if the checked box value is checked. How can I go about this. I have tried using javascript but no success.

The javascript I tried to Use:

<script type=”text/javascript”>
var checkbox = document.getElementById("chbx");
 function foo(){
   if(checkbox.checked){
     alert("meap");
  };
 };
</script>




Aucun commentaire:

Enregistrer un commentaire