在html表单提交后显示div
问题描述:
I am showing up a hidden div which has a textbox using a javascript assigned to a html button. My requirement is
a - keep user entered data in textbox after form submit - able to do it
b - If user added the second hidden div using + Show another
button and once form submit, I would like to display that textbox along with data - able to keep the data but div not displaying (going to hidden state )
my html code:
<form id="main" name="main" action="#text" method="post" >
<div class="wrap-quest-resp" id="fa1">
<div class="input-resp"><span><input class="textbox" id="collect-fa1" name="collect-fa1" type="text" value="<?php if(isset($_POST['collect-fa1'])) { echo htmlentities ($_POST['collect-fa1']); }?>" /></span> </div>
</div>
<div class="wrap-quest-resp" id="fa2" style="display:none;">
<div class="input-resp"><span><input class="textbox" id="collect-fa2" name="collect-fa2" type="text" value="<?php if(isset($_POST['collect-fa2'])) { echo htmlentities ($_POST['collect-fa2']); }?>" /></span> </div>
</div>
<div class="add_remove_column">
<input type="hidden" id="countfa" name="countfa" value="2" readonly>
<button type="button" onClick="AddNewColumn();" id="addfa" > + Show another </button>
</div>
<input id="generate" type="submit" name="script" value="create my symcli script" />
</form>
and javascript to show the hidden div once I click + Show another
function AddNewColumn()
{
var facount = parseInt($('#countfa').val(),3) ;
if( facount < 3)
{
facount = facount+1;
for(i=1;i<3;i++)
{
if( i<facount )
$('#fa'+i).slideDown("fast");
else
$('#fa'+i).slideUp("fast");
}
$('#countfa').val(facount);
}
}
答
I have figured this out and blow code helped me to resolve this
<div class="wrap-quest-resp" id="fa2" style="<?php if(empty($_POST['collect-fa2'])) { echo "display:none;"; } else { echo "display:block;"; } ?>" >