Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changeing value of textfield, IE

    Hi, i'm having some textfields (<input type="text") that i want to change the value of when i press a button. I get this code to work in chrome and firefox but not in internet explorer, somebody know how to fix this?

    HTML-code:
    Code:
    <form action="">
    Förnamn:<br /> 
    <input type="text" id="fornamn" name="fornamn" /><br /><br />
    Efternamn:<br /> 
    <input type="text" id="efternamn" name="efternamn" /><br /><br />
    E-postadress:<br />
    <input type="text" id="epost" name="epost" /><br /><br />
    <br />
    <input type="button" value="Sign up" id="msgbtn" name="btn" onclick="clearContact()" />
    </form>
    and the javascript-code:

    Code:
    function clearContact()
    {
    	fornamn.value = "";
    	efternamn.value = "";
    	epost.value = "";
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    document.getElementById("fornamn").value = "";
    or
    Code:
    document.forms[0].fornamn.value = "";
    and so on

    Quizmaster: Which Asian country is named after King Philip II of Spain?
    Contestant: Mexico

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •