SitePoint Sponsor

User Tag List

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

    Add new attribute to input field

    Hi,

    I need to use Javascript to add some new attributes to an inout field (see below).

    Here is the standard input field:

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

    Here's how I need the input field to look (with the new attributes):

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

    Is this possible?

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var obj=document.getElementById('uploader');
    var att = {"room_name":"room", "album_title":"album", "path":"path"};
    for(var n in att) {
        obj.setAttribute(n, att[n]);
        }

  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 dogFang View Post
    Code:
    var obj=document.getElementById('uploader');
    var att = {"room_name":"room", "album_title":"album", "path":"path"};
    for(var n in att) {
        obj.setAttribute(n, att[n]);
        }
    Hi, I just tried this code but i'm not sure if it worked. The javascript should set those attributes and then the form gets posted after. However, when I look at the posted attributes, they didn't seem to get set by the Javascript so I din't think the code worked.

    Any ideas?

  4. #4
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only name/value pairs, which you are not using, are submitted.

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how would I get the room_name, album_title and path values to be submitted?

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For a start, those aren't standard attributes, so you should not be using them. But they aren't getting "posted" because there is no reason to. The browser doesn't post attributes. It'll post the file and the name, and that's it. That's how forms work (whether GET or POST) - they supply name-value pairs of data.

    If you want all that stuff to somehow get communicated to the server, you need to add a few <input type="hidden"> elements, one for each name-value pair you want.


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
  •