Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    235
    Thanks
    6
    Thanked 21 Times in 20 Posts

    assigning a value to a hidden input

    I have an external JS file which manages a drag and drop list, however I want to change the alert('values I need') to document.getElementById('hiddenfieldid').value = 'value I need'
    Is this possible as that code doesn't seem to be working.

    I've tripple checked the spelling of my input element, and the alert works fine so I know its not the other parts of the JS file.

    Anyone able to help a javascript noob please?

    thanks in advance.
    Andrew Sharman
    Web designer, developer and programmer.

    If you found my post helpful, why not give thanks! :)

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    try do

    Code:
    var hiddenBox = document.getElementById('hiddenfieldid');
    
    hiddenBox.value = "required value";
    
    alert(hiddenBox.value);
    this will show you whether or not the value been written to it

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Could you post a lint to a test page?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    It sounds like you are trying to access the element before the page has loaded. Any code that accesses elements on the page at page load, needs to be executed in an onload event.

    ex:
    Code:
    window.onload=function(){
        //do some stuff with the page elements
    }
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

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