I'm new to jQuery and played a bit with what can I do with radio button. I want to create ONLY one input type when I click the Notice radio button. I already using many way to achieve this, but this is the only way I can do this, you can see the following code.
HTML
<input type="radio" name="radio1" value="Immediate" /> Immediate
<br/>
<input type="radio" name="radio1" id="others" value="Notice" /> Notice me in...
<br />
<div id="inputplace"></div>
jQuery
$(function(){
$("#others").click(function(){
while($("#others").val()=="Notice")
{
var newElement = $(document.createElement('input')).attr({name:"noticeweeks", id:"noticeweeks"});
newElement.appendTo("#inputplace");
$("#others").val("Notice me in...");
}
});
});
With that jQuery, I changed the value of the radio button into "Notice me in...", so the while
function will stop creating a new element since the value has been changed.
Are there any others way to achieve the same result?