Pass a javascript variable value into input type hidden value

后端 未结 8 1189
情歌与酒
情歌与酒 2020-11-27 11:38

I would like to assign value of product of two integer numbers into a hidden field already in the html document. I was thinking about getting the value of a javascript varia

相关标签:
8条回答
  • 2020-11-27 12:07

    Hidden Field :

    <input type="hidden" name="year" id="year">
    

    Script :

    <script type="text/javascript">
         var year = new Date();
         document.getElementById("year").value=(year.getFullYear());
    </script>
    
    0 讨论(0)
  • 2020-11-27 12:10
    //prompts for input in javascript
    test=prompt("Enter a value?","some string");
    
    //passes javascript to a hidden field.
    document.getElementById('myField').value = test;
    
    //prompts for input in javascript
    test2=prompt("Enter a value?","some string2");
    
    //passes javascript to a hidden field
    document.getElementById('myField').value = test2;
    
    //prints output
    document.write("hello, "+test+test2;
    

    now this is confusing but this should work...

    0 讨论(0)
提交回复
热议问题