How do I hide input textfields?

Discussion in 'JavaScript' started by Imozeb, Apr 21, 2010.

  1. #1
    I have an input text-field and I want to hide it after the user hits the submit button. I have all the code ready for this but I can't seem to find a code that will hide a text input field without deleting it. How would I hide it?

    Thanks.

    ~imozeb :)
     
    Imozeb, Apr 21, 2010 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    <input id="yourName" name="yourName" value="John" />

    ...

    document.getElementById("yourName").style.display = "none";
     
    dimitar christoff, Apr 21, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I tried that. It messed up my CSS absolute positioning. Is there another way?
     
    Imozeb, Apr 21, 2010 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    .style.visibility = "hidden" would hide it w/o disruptions to relative elements.
     
    dimitar christoff, Apr 21, 2010 IP
  5. molipoli

    molipoli Peon

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <input type="hidden" name="yourName" value="yourValue" />

    looks like the most suitable solution without even using javascript
     
    molipoli, Apr 21, 2010 IP
  6. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks dimitar. It worked.
     
    Imozeb, Apr 21, 2010 IP