Created
March 14, 2009 17:52
-
-
Save taboularasa/79135 to your computer and use it in GitHub Desktop.
add and delete form elements with jQuery, demo lives here: http://mohdshaiful.wordpress.com/2007/05/31/form-elements-generation-using-jquery/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type=”text/javascript” src=”jquery-latest.pack.js”></script> | |
<script type=”text/javascript” src=”jquery.highlightFade.js”></script> | |
function addFormField() { | |
var id = document.getElementById(”id”).value; | |
$(”#divTxt”).append(”<p id=’row” + id + “‘><label for=’txt” + id + “‘>Field ” + id + ” <input type=’text’ size=’20′ name=’txt[]‘ id=’txt” + id + “‘> <a href=’#’ onClick=’removeFormField(\”#row” + id + “\”); return false;’>Remove</a><p>”); | |
$(’#row’ + id).highlightFade({ | |
speed:1000 | |
}); | |
id = (id - 1) + 2; | |
document.getElementById(”id”).value = id; | |
} | |
function removeFormField(id) { | |
$(id).remove(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p><a href="#" onClick="addFormField(); return false;">Add</a></p> | |
<form action=”#” method=”get” id=”form1″> | |
<input type=”hidden” id=”id” value=”1″> | |
<div id=”divTxt”></div> | |
<p><input type=”submit” value=”Submit” name=”submit”> | |
<input type=”reset” value=”Reset” name=”reset”></p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment