如何从表单获取/复制复选框值到另一个表单

时间:2014-09-15 17:59:29

标签: javascript php jquery html

我试图找出如何从“form1”到“zFormer”获取/复制复选框值 我想我需要一个javascript jquery才能使它工作。将值从form1复制到zFormer的脚本,或者只是将复选框值复制到zFormer。

<!DOCTYPE html>
 <html lang="en">

 <head>
 <script type='text/javascript'              
  src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
 <script type="text/javascript" src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js">         </script>
 <link rel="stylesheet" type="text/css" href="base/jquery-ui.css">
 <style type='text/css'>
  #box_form > *{
font-size:12px;
margin-bottom:15px;
}
 #box_form > p > label{
display:block;
font-size:18px;
 }
  #box_form > p > input, #box_form > p > textarea{
    width:300px;
   }

  </style>
  <script type='text/javascript'>//<![CDATA[ 
   $(window).load(function(){

    $(document).ready(function() {
    $('#box_form').dialog({
    autoOpen: false,
    height: 200,
    width: 350,
    modal: true,
    buttons: [
        {
        text: "Cancel",
        click: function() {
            $(this).dialog("close");
        }},
    {
        text: "Add Selected",
        click: function() {
            $('#zFormer').submit();
        }}
    ]
});
$('#clicky3').button().click(function(e){
    $('#box_form').dialog('open');
});
   });
  });//]]>  

    </script>
    </head>
     <body>


      <form id="form1" name="form1">
      input type="checkbox" name="email'.$emailCount++.'" value="'.email.'"/>
      <input type="hidden" name="name'.$nameCount++.'" value="'.$id.'"/>
       </form>


      <form id="zFormer"  method="POST" action="script/do-something.php" name="zFormer">
      <label for="name">Add Selected</label>
     <select name="list" id="list" class="form-text">
      <option value="">Add To List</option>
      <option value="All">All</option>
      <option value="All">Blog</option>
       <option value="All">Dj</option>
    </select>
      <input type="hidden" name="name'.$nameCount++.'" value="'.$id.'"/>
   <input type="button" name="new_address" id="clicky3" value="Add Selected">
      </form>
     </body>
      </html>

这是功能的图片

enter image description here 谢谢

1 个答案:

答案 0 :(得分:0)

使用jQuery,您可以在复选框或val()属性上使用value方法来获取和设置值。

获取价值的示例:

$(".checkbox").val()document.getElementsByClassName("checkbox")[0].value

设置值的示例:

$(".checkbox").val("my value");document.getElementsByClassName("checkbox")[0].value = "my value";