dongmeixi5311
dongmeixi5311
2015-08-30 16:38
浏览 227

带有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!

图片转代码服务由CSDN问答提供 功能建议

我使用Javascript FormData.Append将值传递给php文件,但我无法使复选框正常工作。 例如

HTML

 &lt; input type =“checkbox”name =“XXX”value =“XXX”/&gt;&lt;  ;标签&gt; XXX选项&lt; /标签&gt; 
   
 
 

JS

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

PHP

  if(  isset($ _ POST ['XXX'])){echo“checked!”;}} 
   
 
 

无论是否勾选方框,我都会收到回复 - 已检查 !

或PHP

  $ XXX = $ _POST ['XXX']; 
   \  n 
 

var $ XXX显示值XXX是否已选中。

如何使用此方法传递复选框,以便我可以区分复选框是否勾选!< / p>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqayok7935
    dqayok7935 2015-08-30 16:48
    已采纳

    Try using

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

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

    点赞 评论

相关推荐