SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing name of input field

    I"ve been having a little problem with a form I've been putting together in php. I've got another post regarding this. But I realized that I could probably solve this all with the use of javascript.

    Basically the only problem I have right now is that I have more than one input field with the same name, so I need to dynamically change this. As it's worked out, I already have some javascript in place that I believe I can piggyback on to accomplish this. I just haven't been able to find a way that would work in this context, most solutions I've found deal with jquery, which this site does not currently have.

    So here's the code that I have in place:
    HTML Code:
    <script type="text/javascript">
    function rad1()
      {
      document.getElementById("check1").style.visibility="visible"
      document.getElementById("check2").style.visibility="hidden"
      document.getElementById("check3").style.visibility="hidden"
      document.getElementById("check4").style.visibility="hidden"
      }
    </script>
    
        <td style="padding-left: 15px;"><input id="radio" type="radio" name="refer_btn" value="A Friend" onclick="rad1()" /></td>
        <td><span id="check1">You're friend's name?:<input type="textfield" name="refer_box"  id="text1" value=""/></span></td>
    It currenty shows the textfield if the radio button is clicked. I have this at a larger scale in with the form and javascript.

    Now, I believe that there's gotta be some way to add the name change commands in this function as well. Something like:

    HTML Code:
    function rad1()
      {
      document.getElementById("check1").style.visibility="visible"
      document.getElementById("check2").style.visibility="hidden"
      document.getElementById("check3").style.visibility="hidden"
      document.getElementById("check4").style.visibility="hidden"
      document.getElementById("text1").obj.name ="refer_box"
      document.getElementById("text2").obj.name ="null"
      document.getElementById("text3").obj.name ="null"
      document.getElementById("text4").obj.name ="null"
      }
    Obviously that doesn't work, but this should just be a matter of using the wrong verbaige, right?



    Re: Wow! it appears that this works. Could have sworn I tried that already.

    document.getElementById("text1").name ="refer_box"
    Last edited by NT_cookies; Apr 3, 2012 at 08:43. Reason: Found solution, update

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,837
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    In ternet Explorer doesn't allow you to change the name of an input field after it has been created. To be able to change the name in IE you'd need to delete the input field and add a new one in its place.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •