SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change ACTION & NAME In Javascript?

    Can I change the action and name of an element using javascript

    <form ACTION=sitepoint.com id=form1><input NAME=variable id=input1></form>

    document.getElementById('form1').action=anothersite.com
    document.getElementById('input1').name=anotherName

    ???

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes
    Code:
    <form action="http://www.sitepoint.com" id="form1">
    <input type="button" value="change variable name" onclick="document.getElementById('input1').setAttribute('name','newname')">
    <input type="button" value="change action of this form" onclick="document.getElementById('form1').setAttribute('action','http://www.google.com')">
    <input type="button" value="test my name" onclick="alert(this.name)" name="variable" id="input1">
    <input type="submit" value="test action">
    </form>

  3. #3
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a charm. Thanks much!

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't setAttribute screw up in IE occasionally?

    Dave

  5. #5
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just in same case like setAttribute - onclick, style, name (one uppercase letter solution = Name), usemap (useMap) and so one. Mostly works normally.


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
  •