如何通过表单传递javascript变量?

时间:2014-09-13 19:21:59

标签: javascript html parameter-passing html-form-post

如何传递这两个变量val_1& val_2通过表单提交到函数initComparison()

这是我的代码:

<form action="" onsubmit="">    
 <select name="val_1">
   <option value="x">X</option>
   <option value="y">Y</option>

 <input type="text" value="Enter the product id" name="val_2">
</form>
<script type="text/javascript"> $(document).ready(function(){
    initComparison('val_1','val_2','abc','def');
 });</script>

1 个答案:

答案 0 :(得分:0)

使用类似的东西

      <form action="" onsubmit="">    
        <select name="val_1" id="val_1">
            <option value="x">X</option>
            <option value="y">Y</option>
         </select>
          <input type="text" value="Enter the product id" name="val_2" id="val_2">
          <input type="button" name="submit" value="submit" id="send">
      </form>

         <script type="text/javascript"> 
             $("#send").click(function(){
                 var var1=$("#val_1").val();
                 var var2=$("#val_2").val();

             initComparison(val_1,val_2,'abc','def');
          });
         </script>