Web Analytics Made Easy -
StatCounter Assign Variable to Hidden Field Value - CodingForum

Announcement

Collapse
No announcement yet.

Assign Variable to Hidden Field Value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assign Variable to Hidden Field Value

    I am new to javascript and am doing the trial by fire thing here. I am trying to set the value of MyHiddenField to myvar1. Any help would be greatly appreciated.

    <script>

    var myvar1 = "My new value"

    </script>

    <form name="MyForm" action="thispage.php" method="post">
    <input type="hidden" name="MyHiddenField" value="" />
    </form>
    David A. Prichard

    Computer Support Tampa - Computer Support Chicago - Technology Blog

  • #2
    My guess would be it would be done like so:

    Code:
    <script type="text/javascript">
    window.onload = function() { // execute function after page has finished loading.
        var myvar1 = "My new value";
        document.MyForm.MyHiddenField.value = myvar1; //assign value to hidden input element.
    }
    </script>
    Hope this helps.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

    Comment


    • #3
      Awesome, thank you. Yeah, I was trying document.write in the value field, but it was coming out exactly like I typed it instead of the value of the variable.
      David A. Prichard

      Computer Support Tampa - Computer Support Chicago - Technology Blog

      Comment

      Working...
      X