ProxyProtocol
ProxyProtocol

Reputation: 9

Getting rid of Value attribute of a textBox when using clone method in jQuery

I'm having a problem with this form I'm working on. Whenever I add, or refresh the page, the values are still there. I believe this is because the clone method copies the value attribute from the textBox. Is there any way I can get rid of them when I add another textBox?

<html>
  <head>
    <title>JQuery Example</title>
    <script type="text/javascript" src="jquery-1.4.js"></script>
    <script type="text/javascript">


      function removeTextBox()
      {
          var childCount = $('p').size() //keep track of paragraph childnodes

          //this is because there should always be 2 p be tags the user shouldn't remove the first one
           if(childCount != 2)   
          {
            var $textBox = $('#textBox')
            $textBox.detach()

          }

      }


      function addTextBox()
      {

        var $textBox = $('#textBox')
        var $clonedTextBox = $textBox.clone()

        //document.getElementById('textBox').setAttribute('value', "")

        $textBox.after($clonedTextBox)



      }
    </script>
  </head>
  <body>
    <form id =
          method="POST"
          action="http://cs.harding.edu/gfoust/cgi-bin/show">

    <p id= "textBox">
        Email:
        <input type = "text" name="email" />
        <input type ="button" value ="X" onclick = "removeTextBox()"/>
    </p>

      <p>
        <a href="javascript:addTextBox()">Add another email</a>
      </p>
      <input type="submit" value="submit"/>
    </form>
  </body>
</html>

Upvotes: 1

Views: 837

Answers (1)

Kyle Butt
Kyle Butt

Reputation: 9790

The Following addition should work:

var $clonedTextBox = $textBox.clone();
$($clonedTextBox).val('');

Upvotes: 1

Related Questions