Results 1 to 10 of 10

Thread: how to set value for hidden field

  1. #1
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to set value for hidden field

    hi to all

    in my form there exist an hidden field. how to set a value to that field using javascript

    regards

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well In JavaScript -

    <html>
    <body>
    <input type="hidden" id="hiddenbox">
    <script>
    document.onload=function() {
    document.getElementById('hiddenbox').value="The Value Here"
    }
    </script>
    </body>
    </html>

    In Plain HTML -

    <html>
    <body>
    <input type="hidden" value="The Value Here" id="hiddenbox">
    </body>
    </html>

    Hope This Helps...

  3. #3
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your reply

    i want to set the value hidden field when ever i click on a hyper link and also i want to set that hidden field value with this hyperlink value. is it possible.

    regards

  4. #4
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By value do you mean the href(address) or the text <a href="sadsasdsas.htm">WORDS</a>?

  5. #5
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i want send text value

  6. #6
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK... -

    <html>
    <body onclick="setavalue()">
    <a href="#">OK</a>
    <a href="#">What</a>
    <input type="hidden" id="hiddenbox">
    <script>
    function setavalue() {
    if (event.srcElement.tagName=="A") {
    document.getElementById('hiddenbox').value=event.srcElement.innerText}
    }
    </script>
    </body>
    </html>

    Though this may not work in other browsers then IE as I have not used e ...

  7. #7
    Join Date
    Apr 2007
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your reply


    in my jsp page there exist hyper links from "A" to "Z" and when ever i click on any one of the letter once again it calls itself with a parameter as that clicked character.while loading i get the value which is passed through hidden field and executes a sql command and the result is plcaed below those hyper links.


    regards

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <html>
    <body onclick="setavalue()">
    <a href="#">OK</a>
    <a href="#">What</a>
    <input type="hidden" id="hiddenbox">
    <script>
    function setavalue() {
    if (event.srcElement.tagName=="A") {
    document.getElementById('hiddenbox').value=event.srcElement.innerText}
    }
    </script>
    </body>
    </html>
    Inefficient (you only need to handle clicks on <a> elements, not any element), and yes, IE-only. You'd want to do something like this:
    Code:
    <script type="text/javascript">
      onload = function() {
        var f = function() {
          document.getElementById("hiddenbox").value = this.text;
        };
        for(var i = 0, a = document.links; i < a.length; ++i)
          a[i].onclick = f;
      };
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Input fields don't have an "innerText" property anyways. They're tags which don't need to be closed.

    document.getElementById("hiddenbox").value = this.text;
    Calling that from an anchor... does an anchor even have a "text" property?
    - Mike

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Calling that from an anchor... does an anchor even have a "text" property?
    Indeed.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •