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.

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

The Form input:

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

The JS code is triggered by an “onchange” event on a select menu.

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…

Yes the attributes are not getting set. Not sure how I can check if the element in question is loaded yet?


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