<html> | |
<head> | |
<title>jQuery add / remove textbox example</title> | |
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> | |
<style type="text/css"> | |
div{ | |
padding:8px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>jQuery add / remove textbox example</h1> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var counter = 2; | |
$("#addButton").click(function () { | |
if(counter>10){ | |
alert("Only 10 textboxes allow"); | |
return false; | |
} | |
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter); | |
newTextBoxDiv.after().html('<label>Textbox #'+ counter + ' : </label>' + | |
'<input type="text" name="textbox' + counter + | |
'" id="textbox' + counter + '" value="" >'); | |
newTextBoxDiv.appendTo("#TextBoxesGroup"); | |
counter++; | |
}); | |
$("#removeButton").click(function () { | |
if(counter==1){ | |
alert("No more textbox to remove"); | |
return false; | |
} | |
counter--; | |
$("#TextBoxDiv" + counter).remove(); | |
}); | |
$("#getButtonValue").click(function () { | |
var msg = ''; | |
for(i=1; i<counter; i++){ | |
msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val(); | |
} | |
alert(msg); | |
}); | |
}); | |
</script> | |
</head><body> | |
<div id='TextBoxesGroup'> | |
<div id="TextBoxDiv1"> | |
<label>Textbox #1 : </label><input type='text' id='textbox1' > | |
</div> | |
</div> | |
<input type='button' value='Add Button' id='addButton'> | |
<input type='button' value='Remove Button' id='removeButton'> | |
<input type='button' value='Get TextBox Value' id='getButtonValue'> | |
</body> | |
</html> |
Monday, 5 November 2012
jQuery dynamic textbox example
Subscribe to:
Post Comments (Atom)
What should you required to learn machine learning
To learn machine learning, you will need to acquire a combination of technical skills and domain knowledge. Here are some of the things yo...
-
Introduction This article is aimed at people who are new to the world of Raspberry Pi [Like me]. It gives an idea about what Raspberry P...
-
A simple set of question framings was defined by Kipling in his immortal poem: I have six faithful serving men They taught me all ...
-
In this article we explain how to attain the goal of applying the SAP OpenUI5 user interface library to create line-of-business applicatio...
No comments:
Post a Comment