issues with verifying form data in a popup window using jquery

Hello, I'm struggling to understand why this form isn't validating upon submission. I've chosen not to use jQuery's built-in validate function in this case. Essentially, the code is designed to show an error image and prevent form submission if a field is left blank.

The form itself is contained within a modal window that fades in upon clicking a button and can be closed. However, the issue I'm facing is that the form is automatically processed upon submission instead of jQuery displaying any errors.

Below is the HTML code for the form:

<div id="blanket" style="display:none;" ></div>
<div id="window" style="display:none;" >
    <div id="close"><a class="close" id="hidetrigger" href="#"><img src="../images/close-btn.png" /></a></div>
    <div class="formtitle"><div class="required">Please fill in required fields (<span class="asterix">*</span>) below!</div></div>
    <div class="clear"></div>
    <form id="quoteform" method="post" action="/" enctype='multipart/form-data'>
    <p><label for="name" class="label">Name(<span class="asterix">*</span>):</label>
       <input type="text" class="fields" name="name"  />
       <label class="error" for="name" id="name_error"></label>
       <select name="budget" class="dropdownfieldbudget">
                      <option value="0">Please Select...</option>
                      <option value="N/A">N/A</option>
                      <option value="$1-200">$0 - $200</option>
                      <option value="$200-500">$200 - $500</option>
                      <option value="$500 +">$500 +</option>
                    </select>
    <label for="budget" class="labelbudget">Budget(<span class="asterix">*</span>):</label>
    <label class="error" for="budget" id="budget_error"></label>

    </p>

    <p><label for="email" class="label">Email(<span class="asterix">*</span>):</label>
        <input type="text" class="fields" name="email"  />
        <label class="error" for="email" id="email_error"></label>
        <input type="file" name="file" class="fileattach" />
        <label for="file" class="labelfile">File(<span class="asterix">.zip</span>):</label>
        <label class="error" for="file" id="file_error"></label>
    </p> 

    <p><label for="organisation" class="label">Organisation:</label>
        <input type="text" class="fields" name="organisation" />
               <label class="error" for="type" id="type_error"></label>
       <input type="checkbox" class="checkbtn" name="type" value="Graphic Design" /><span class="checkbtn">Graphics</span>
       <input type="checkbox" class="checkbtn" name="type" value="Conversion" /><span class="checkbtn">Conversion</span>
       <input type="checkbox" class="checkbtn" name="type" value="Web Design" /><span class="checkbtn">Web Design</span>
       <label for="budget" class="labelwork">Type(<span class="asterix">*</span>):</label>
    </p>


    <p><label for="country" class="label">Country:</label>
        <input type="text" class="fields" name="country" ></p>
    <p><label for="comment" class="label">Comments:</label>
       <textarea name="comment" class="txtfield" ></textarea> 
    <p><label for="hearabout" class="labelhear">Where did you hear about us?</label>
                    <select name="hearabout" id="hearabout" class="dropdownfield">
                      <option value="0">Please Select..</option>
                      <option value="Another Website">Another Website</option>
                      <option value="Email">Email</option>
                      <option value="Online Advertisements">Online Advertisements</option>
                      <option value="Printed Media">Printed Media</option>
                    </select></p> 

    <p><label style="height:45px" for="submit" class="label"></label>
        <div class="submitwrapper"><input type="submit" class="submitbtn" value="SUBMIT" name="submit" > <div class="success"><span class="blue"></span></div></div></p>  
        <div class="clear"></div>                     

    </form>
</div>

And here is the jQuery code:

$(".submitbtn").click(function() {
    $(".error").hide(); 
    var name = $("input#name").val();
        if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
    var email = $("input#email").val();
        AtPos = email.indexOf("@")
        StopPos = email.lastIndexOf(".")
    if (AtPos == -1 || StopPos == -1) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
}); 

Answer №1

Make sure to eliminate the action attribute in your form code

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Abstract forms on the canvas are dancing in a strange and unusual rhythm

As a beginner in web design, I've made progress but still have questions. Can someone help explain this to me? Here is how a specific section on my website is set up: https://i.sstatic.net/8ntpR.png I'm working on splitting the screen with 40% ...

"An Unanticipated SyntaxError occurred due to a misplaced token in the doctype declaration

I find myself revisiting a small import script, which I had to divide due to the large amount of data. Initially, there's a start.php file with an impressive ajax action and dbactions.php that handles all the heavy lifting. The script kickstarts by ...

merging a pair of jquery methods

function combineFunctions(id) { $ogzu = id; jQuery("#okay").load("ajax_post_category.php?okay="+id+""); $ugur = id; } I am trying to combine these two functions into one. I have tried several ways but haven't been ...

An error message is displayed when attempting to retrieve a json response

After implementing my flask app, I noticed that the following code snippet is being returned: return json.dumps({'status': 'OK','url': 'www.blahg.com'}) Upon inspecting my javascript code, I found it to be structur ...

Conceal two DIV elements if one of them is empty

My slideshow has thumbnails connected to each slide. There are 10 DIVs representing the slides like this... <div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image --> <?php while ($row = mysql_fetch_array($query ...

Make a div with absolute positioning overflow outside of a div with relative positioning that is scrollable

I am facing an issue with two columns positioned side by side. The right column contains a tooltip that overflows to the left on hover. Both columns are scrollable and relatively positioned to allow the tooltip to follow the scroll. However, the tooltip is ...

Exploring touch interactions using D3.js and TUIO

I'm currently facing a challenge with implementing multi-touch functionality and the d3.slider in my D3 Map. You can see the current state of my project in this video. With the d3 slider, I can spawn points and navigate around the map using touch even ...

What is the best method to insert an item into a SQL database using jQuery and AJAX through a web service?

I have a web service that contains two methods (select, insertdata). I am trying to insert a record into a SQL database using jQuery, but my current code is not working. Can someone please assist me with this? Description of My Web Service: SqlConnection ...

JQuery failing to validate the form

Whenever I try to validate a form by clicking the submit button, it seems to ignore the validation altogether and proceeds to post the entered data to the next page. Below are the validation codes: <script> $(document).ready(function() { $("#re ...

The function is defined, but it cannot be set to null

Having trouble understanding this error message "Cannot set properties of null." I'm attempting to update the innerHTML with the output text from four functions that my button triggers. However, it seems to be stopping at the first function now even t ...

Apply jQuery addClass to the first child option in a multi-select dropdown menu

I'm looking to dynamically add the class userFirstChoice to the first option a user selects from a dropdown list. The CSS for .userFirstChoice is designed to visually highlight the first choice in the list. Is there a way to achieve this using jQuery ...

develop a submission form using jquery

I am looking to create a submit action where clicking the submit button does not refresh the page. Instead, the data inputted in div1 will be sent to kanjiconverter.php and displayed in div2 using <?php echo $newkanji ?>. There are three forms on thi ...

I'm curious about the specific sequence of CSS properties order recommended by Stylelint. Where can I locate

With Stylelint's CSS order option enabled, I'm having trouble getting Visual Studio Code to display the errors. Where can I locate the declaration/property order being used? Below is a snippet of my .stylelintrc.js configuration file: module.exp ...

What is the best way to display a child div without impacting the position of other elements within the same parent container?

As I work with a div html tag within a login form, encountering an error inside this form has presented a challenging issue. The error div sits at the top of its parent div, and ideally, upon activation, should remain within the form div without disrupting ...

Guide on removing the <hr/> tag only from the final list item (li) in an Angular

This is my Angular view <li class= "riskmanagementlink" ng-repeat="link in links"> <h3> {{link.Description}} </h3> <a> {{link.Title}} </a> <hr/> </li> I need assistance with removing the hr tag for the l ...

Is the JQuery ajax xhr fully completed before it begins?

Having a long script that can take a few minutes to execute, I decided to create a progress bar to display the current state. However, I encountered a problem where xhr evt.loaded/evt.total (30/30) returns 1 (100%) before the long script starts executing. ...

Stop the execution of javascript code based on the screen width

On my website, I have two menus located in different sections of the page. One menu is shown when the screen width is greater than 555px, while the other menu appears when the screen width is less than or equal to 555px. Although the menus are essentially ...

ASP.Net MVC 3 incorporating the powerful features of JQGrid

Upon researching the JQGrid control, I made the decision to incorporate it into one of my ASP.Net MVC 3 Web applications. To start off, I followed Phil Haack's tutorial which was very helpful. I then attempted to implement a similar setup in my appl ...

Is there a way to position the icon in the top left corner within the image using Vue and CSS?

I am currently working on a Vue project and I am attempting to create a row of images with an icon positioned at the top left corner of each image. Here is my code snippet: <div v-for="(image, index) in images" :key="index" class=&q ...

Is there a way to trigger a modal popup when hovering over a Bootstrap 5 card?

After coming across a handy template online, I decided to implement a modal pop-up feature when hovering over cards using Bootstrap 5. Here's what I have so far: class SavedEpisodes extends Component { $(function() { $('[data-toggle=&qu ...