Very simple question

Discussion in 'JavaScript' started by progfrog, Jan 20, 2009.

  1. #1
    How can I make a value of an input text to vanish after pressing a button?

    this is the code i wrote but it doesn't work..
    
    
    
    <html>
    <head>
    <script type="text/javascript">
    function regel(z)
    {
    var x=document.getElementById(z)
    x.style.visibility="hidden"///i thought thi should do the job..
    
    
    
    }
    
    </script>
    </head>
    <body>
    
    <input type="text" id="t1" style="width:200px; height:200px;">
    
    <input type="button" value="right->>" onclick="regel('t1')"> </button>
    
    
    </body>
    </html>
    
    
    
    
    
    
    Code (markup):

    need u quickly!!!
     
    progfrog, Jan 20, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    if you want the value of an input to vanish...

    document.getElementById("t1").setAttribute("value", "");
     
    dimitar christoff, Jan 20, 2009 IP
  3. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    actually.it works on ie but not on ff.. any idea why?
     
    progfrog, Jan 20, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    your code? no idea, why not use firebug to troubleshoot it? you can always do:

    console.log(x.style) and see if it is indeed a style collection.

    otherwise, just tested:
    <input id="t1" value="arse" />
    
    
    <script language="JavaScript">
    document.getElementById("t1").setAttribute("value", "");
    </script>
    
    PHP:
    works fine
     
    dimitar christoff, Jan 20, 2009 IP
  5. symbol.software

    symbol.software Member

    Messages:
    138
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    48
    #5
    document.getElementById(z).value = "";
     
    symbol.software, Jan 20, 2009 IP
  6. bbrez1

    bbrez1 Banned

    Messages:
    208
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Like symbol said.

    
    <html>
    <head>
    <script type="text/javascript">
    function regel(z)
    {
      document.getElementById(z).value = ""; // will change to an empty string
    }
    </script>
    </head>
    <body>
    <input type="text" id="t1" style="width:200px; height:200px;">
    <input type="button" value="right->>" onclick="regel('t1')"> </button>
    </body>
    </html>
    
    Code (markup):
     
    bbrez1, Jan 23, 2009 IP