Advertisement
atmoner

Add/remove Jquery

Jan 13th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <script>$(function() {
  2.         var scntDiv = $('#p_scents');
  3.         var i = $('#p_scents p').size() + 1;
  4.        
  5.         $('#addScnt').live('click', function() {
  6.                 $('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
  7.                 i++;
  8.                 return false;
  9.         });
  10.        
  11.         $('#remScnt').live('click', function() {
  12.                 if( i > 2 ) {
  13.                         $(this).parents('p').remove();
  14.                         i--;
  15.                 }
  16.                 return false;
  17.         });
  18. });</script>
  19.  
  20. <style>
  21. * { font-family:Arial; }
  22. h2 { padding:0 0 5px 5px; }
  23. h2 a { color: #224f99; }
  24. a { color:#999; text-decoration: none; }
  25. a:hover { color:#802727; }
  26. p { padding:0 0 5px 0; }
  27. input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
  28. </style>
  29.  
  30.  
  31. <div id="ContentWrapper">  
  32. <h2><a href="#" id="addScnt">Add Another Input Box</a></h2>
  33. <form id="cat" method="POST" action="">
  34. <div id="p_scents">
  35.     <p>
  36.         <label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt" value="" placeholder="Input Value" /></label>
  37.     </p>
  38. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement