SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Set a custom attribute on form input field

    Hi Guys!

    I am trying to use SetAttribute to append a custom attribute to a form input. The code is below. Please help.

    Code JavaScript:
    function getpostdata(){
    	// Append the values
    	var uploader = document.getElementById("uploader");
    	uploader.setAttribute("room_name", "test");
    	uploader.setAttribute("album_title", "test");
    }

    The Form input:

    Code HTML4Strict:
    <input id="uploader" type="file" auto="false" buttoncaption="Upload" multi="true" afterupload="link" maxsize="204800" />

  2. #2
    SitePoint Evangelist TommiChi's Avatar
    Join Date
    Oct 2008
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    What exactly is the problem? the attributes are not set? It would be expected behavior if you run the script before the element in question is not yet loaded in the DOM

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TommiChi View Post
    Hi,

    What exactly is the problem? the attributes are not set? It would be expected behavior if you run the script before the element in question is not yet loaded in the DOM
    Yes the attributes are not getting set. Not sure how I can check if the element in question is loaded yet?

  4. #4
    SitePoint Evangelist TommiChi's Avatar
    Join Date
    Oct 2008
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, can you provide just a little more background info:
    - What action triggers the JS code?
    - If the code executes as the page is opening, where is the script located? In the header, the body, or does it execute on window.onload?

    If you could post a bit more source code, or at least a workable sample code, that would be helpful....

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TommiChi View Post
    OK, can you provide just a little more background info:
    - What action triggers the JS code?
    - If the code executes as the page is opening, where is the script located? In the header, the body, or does it execute on window.onload?

    If you could post a bit more source code, or at least a workable sample code, that would be helpful....
    The JS code is triggered by an "onchange" event on a select menu.


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
  •