Passing javascript variable to html textbox

前端 未结 6 1889
旧巷少年郎
旧巷少年郎 2020-12-14 04:53

i need help on html form.

I got a javascript variable, and I am trying to pass the variable to a html form texbox. I want to display the variable on the textbox dyna

相关标签:
6条回答
  • 2020-12-14 05:18

    You could also use to localStorage feature of HTML5 to store your test value and then access it at any other point in your website by using the localStorage.getItem() method. To see how this works you should look at the w3schools explanation or the explanation from the Opera Developer website. Hope this helps.

    0 讨论(0)
  • 2020-12-14 05:21

    Pass the variable to the form element like this

    your form element

    <input type="text" id="mytext">
    

    javascript

    var test = "Hello";
    document.getElementById("mytext").value = test;//Now you get the js variable inside your form element
    
    0 讨论(0)
  • 2020-12-14 05:21

    This was a problem for me, too. One reason for doing this (in my case) was that I needed to convert a client-side event (a javascript variable being modified) to a server-side variable (for that variable to be used in php). Hence populating a form with a javascript variable (eg a sessionStorage key/value) and converting it to a $_POST variable.

    <form name='formName'>
    <input name='inputName'>
    </form>
    
    <script>
    document.formName.inputName.value=var
    </script>
    
    0 讨论(0)
  • 2020-12-14 05:31

    instead of

    document.getElementById("txtBillingGroupName").value = groupName;

    You can use

    $("#txtBillingGroupName").val(groupName);

    instead of groupName you can pass string value like "Group1"

    0 讨论(0)
  • 2020-12-14 05:32
    document.getElementById("txtBillingGroupName").value = groupName;
    
    0 讨论(0)
  • 2020-12-14 05:41
    <form name="input" action="some.php" method="post">
     <input type="text" name="user" id="mytext">
     <input type="submit" value="Submit">
    </form>
    
    <script>
      var w = someValue;
    document.getElementById("mytext").value = w;
    
    </script>
    
    //php on some.php page
    
    echo $_POST['user'];
    
    0 讨论(0)
提交回复
热议问题