1

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>
2
  • 1
    return false in your submit callback. Commented Oct 22, 2012 at 11:14
  • Post some codes what you've tried Commented Oct 22, 2012 at 11:21

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.