I am working on a project in which I need to make an HTML page with couple of radio buttons.
- First radio button is,
INSERT
. As soon as I click INSERT radio button, I would like to show three text box just below the INSERT radio button. First textbox isdatacenter
, second textbox isnode
and third textbox isdata
. - Second radio button is,
UPDATE
. As soon as I click UPDATE radio button, I would like to show same above three text box just below the UPDATE radio button. - Third radio button is,
DELETE
. As soon as I click DELETE radio button, I would like to show only one text box just below the DELETE radio button. In this one text box will benode
. - Fourth radio button is,
PROCESS
. As soon as I click PROCESS radio button, I would like to show four text box just below the PROCESS radio button. In this first textbox will bedatacenter
, second textbox will benode
, third textbox will beconf
and fourth textbox will bedata
.
I am able to make first two radio button work (insert and update) but somehow I am not able to understand how do I make last two radio button work.
Below is my HTML
<form method="post" action="testOperation">
<input type="hidden" name="name" id="dynamicName">
<input class="changeAction" type="radio" name="tt" value="Insert" div-id="insert"/> Insert
<div id="insert" class="changeable"></div>
<br/> <input class="changeAction" type="radio" name="tt" value="Update" div-id="update"/> Update
<div id="update" class="changeable"></div>
<br/>
<input type="submit">
</form>
Below is my jquery -
$(document).ready(function(){
$(".changeAction").on("click", function(){
$('.changeable').html('')
var divId = $(this).attr("div-id");
$("#dynamicName").val(divId);
divId = "#"+divId;
var myInput = '<label for="Datacenter"> Datacenter </label> <input type="text" name="datacenter" size="20" /> <label for="Node"> Node </label> <input type="text" name="node" size="20" /> <label for="Data"> Data </label> <input type="text" name="data" size="100"/>'
$(divId).html(myInput);
})
})
And here is my jsfiddle. It will be of great help if anyone can provide any jsfiddle example?
Change your html code to this
try this code in javascript part,
SEE FIDDLE DEMO