dongmeixi5311 2015-08-30 16:38
浏览 425
已采纳

带有FormData.Append的复选框

I am using Javascript FormData.Append to pass values to a php file, but I cannot get check boxes working. For Example

HTML

<input type="checkbox" name="XXX" value="XXX" /><label>XXX Option</label>

JS

FormData.append( 'XXX', $('input[name=XXX]').val());

PHP

if (isset($_POST['XXX'])) {    echo "checked!";}

Whether I check the box or not, I get the response - checked!

OR PHP

$XXX= $_POST['XXX'];

The var $XXX shows value XXX whether checked or not.

How can I pass checkboxes using this method so I can differentiate if the checkbox is ticked or not!

  • 写回答

1条回答 默认 最新

  • dqayok7935 2015-08-30 16:48
    关注

    Try using

    document.getElementsByName('XXX')[0].checked

    To check the status of whether it's checked or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?