Creating input when checking/clicking radio button 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

&lt;input type="radio" name="radio1" value="Immediate" /&gt; Immediate
&lt;br/&gt;
&lt;input type="radio" name="radio1" id="others" value="Notice" /&gt; Notice me in...
&lt;br /&gt;
&lt;div id="inputplace"&gt;&lt;/div&gt;


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?
There's no need to use a while loop, as you only want to add the element once, after which the condition won't hold anymore. That's what if is for.
There's a shorter way to create a new element


So I get to:

$(function() {
    $("#others").click(function() {
         if ($("#others").val() == "Notice") {
            var newElement = $('&lt;input&gt;')).attr({name:"noticeweeks", id:"noticeweeks"});   
            newElement.appendTo("#inputplace");    
            $("#others").val("Notice me in...");
        }
    });
});