SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Montreal, Canada
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing values of form elements with JS

    Hi All,

    Let's say I have the following code:

    Code:
    <FORM ACTION="Whatever.htm">
    Name: <INPUT TYPE=TEXT id="MyName" size=30><BR>
    Age:  <INPUT TYPE=TEXT id="MyAge" size=3><BR>
    File: <input type=file id="MyFile" size=50><br>
    <INPUT TYPE=SUBMIT name="submit" VALUE="Submit">
    </FORM>
    I can access and change the values of "MyName" and "MyAge" with the DOM with something like this

    Code:
    document.getElementById("MyName").setAttribute("value", "Joe");
    document.getElementById("MyAge").setAttribute("value", 31");
    I can't change "MyFile" input value. It doesn't work. Is this by design (you can't do that!!!) or am I doing it wrong?

    Thanks for you time.

    Mike

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe it is a security risk to be able to make a default value. I tried all of my tricks and I couldn't get a default value. It 'HAD' to be entered by the user.

    I dont have any experience with file fields, I have never used one so there may be someone else who can better help you.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Montreal, Canada
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Maelstrom,

    I've tried a lot of tricks myself.

    If you type in manually a URL (www.microsoft.com for example) of whatever (It's a boy buddy!!!) and attach an alert method on the submit button you get the value of the field.

    But it seems you can't set the value...

    Mike

  4. #4
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by ALSLG
    Hi Maelstrom,

    I've tried a lot of tricks myself.

    If you type in manually a URL (www.microsoft.com for example) of whatever (It's a boy buddy!!!) and attach an alert method on the submit button you get the value of the field.

    But it seems you can't set the value...

    Mike
    I would assume its readonly. Because that field access's the clients computer correct??? If you could se the value you could grab stuff off of their end without them knowing. I could see some serious security problems with what you wish to do
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


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
  •