Reputation: 27
I am trying to show a div on click of a submit button but when I am submitting the div is shown for the moment till the page reloads. After the page reload the div fades away. I need to stop that fading. How to do it in JavaScript?
The code is as:
<div class="main" align="center" data-dojo-type="dijit/TitlePane" data-dojo-props="title: 'Report Generation'">
<form action="response.jsp" method="post">
<h2></h2>
<select data-dojo-type="dijit/form/ComboBox" id="sel" name="sel" required="true">
<option value=""><---Select the Sources---></option>
<option value="">All</option>
<% String tss=fa.myresult();
%>
<option value=""><%=tss%></option>
</select><br><br>
<select data-dojo-type="dijit/form/ComboBox" id="linkrec" name="linkrec" required="true">
<option value=""><---Select The Operation---></option>
<option value="">Linkages</option>
<option value="">Total No. of records</option>
</select><br><br>
<button data-dojo-type="dijit/form/Button" type="Submit" onClick=check();>Search</button></form>
</div>
<div class="child" id="p2" style="display:none" data-dojo-type="dijit/TitlePane" data-dojo-props="title: 'Result'">
<% String a1=fa.getsrc();
String name=request.getParameter("sel");
String src=request.getParameter("linkrec");%>
The Selected source is ---><%=name %><br><br>
<b>The Selected operation is--><%=src %></b><br>
<b>The Source <%=name%> Has <%=src%>---><%=a1%></b>
</div>
<script>
function check()
{
usersrc=document.getElementById("sel").value;
userselect=document.getElementById("linkrec").value;
if(usersrc=="<---Select the Sources--->"|| userselect=="<---Select The Operation--->")
{
alert("Select src and records");
}
else if (usersrc=="All" && userselect=="Linkages")
{
document.getElementById('p2').style.display ='';
}</script>
Upvotes: 1
Views: 1718
Reputation: 205
Just add return false to your onSubmit
<input type="submit" name="submit" value="Save" onclick="return showdiv();"/>
** in javascript**
function showdiv()
{
var error = false;
//validate your form.
if(error == true){ return true;}
else
{
//show div
return false;
}
}
Upvotes: 1