0

I want to know how I show a specific div at a specific function only. I want to show the following div called "cd-popup" in my javascript function called "validateForm()".

<script type="text/javascript">
   function validateForm() {
      var x = document.getElementById("email-id").value;
      if ( x == null || x == "" ) {
         $('.cd-popup').addClass('is-visible');
      }
   }
</script>
<div class="cd-popup" role="alert">
   <div class="cd-popup-container" style="margin-left: 10%;">
      <p style="color: #5b5b5b;">Are you sure you want to delete this element?</p>
      <a href="#0" class="cd-popup-close img-replace">Close</a>
      <!-- <img id="close"  style="position: absolute;right: -14px;top: -14px; cursor: pointer;" onclick ="div_hide()"> -->
   </div>
   <!-- cd-popup-container -->
</div>
<!-- cd-popup -->

Also I have entered the email div where I called to the function through "onblur"

<!-- EMAIL -->
<div class="col-lg-6 col-xs-6">
   <div class="form-group">
       <input type="email" class="form form-control email requiretop" placeholder="Your email" name="email" id="email-id" onblur="return validateForm()">
   </div>
</div>

I want to show the div cd-popup only when you call the validateForm() method

1
  • So, let me get this straight: do you want to show the div cd-popup only when you call the validateForm() method? Commented Nov 3, 2014 at 8:35

1 Answer 1

1

This is a simple show-hide div phenomena, jQuery .show() and .hide() elements are the perfect solution to this. Just modify your script in the following way:

<script type="text/javascript">
function validateForm() {
    var x = document.getElementById("email-id").value;
    if ( x == null || x == "" ) {
        $('.cd-popup').show();
    }
    else{
        $('.cd-popup').hide(); 
    }
}

</script>  
Sign up to request clarification or add additional context in comments.

2 Comments

This is not working there is a class called "is-visible" and its come from the template
Is is-visible a css class? If so, then you can detach the referenced css file from your home page.

Your Answer

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