Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6693995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:03:02+00:00 2026-05-26T06:03:02+00:00

This form allways submit, never javascript stop with the errors. What is wrong? thanks

  • 0

This form allways submit, never javascript stop with the errors. What is wrong?

thanks in advance 😉

I put the onsubmit return valida(this)…. and the javascript code seems well

<form name="formulario" id="formulario" method="POST" action="<%=request.getContextPath()%>/altaanuncio" onSubmit="return valida(this)">


function valida(f) {

        if (f.marca.selectedIndex==0){
            $('#errores').html('Seleccione la marca.');
            f.marca.focus();
         return false;
    }

        else if(f.garantia.value == ""){
            $('#errores').html('Introduzca meses de garantía');
            f.garantia.focus();
                return false;
        }

        else if(f.pvpofertado.value == ""){
            $('#errores').html('Introduzca el precio del coche');
            f.pvpofertado.focus();
                return false;

        }

     return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:03:03+00:00Added an answer on May 26, 2026 at 6:03 am

    I think you’re trying to call jQuery functions on plain JS elements. Try this:

    // When the DOM is ready:
    $(document).ready(function() {
    
        // Attach submit event listener to form (== onSubmit)
        $('#formulario').submit(function(event) {
    
            // Get the jQuery object for the 'marca' field:
            var marca = event.target.children('#marca');
    
            if (marca.attr('selectedIndex') === 0) {
                $('#errores').text('Seleccione la marca.');
                marca.focus(); // <--this now works because it's a jQuery object.
                event.preventDefault(); // instead of return false;
            }
        });
    });
    
    <form id="formulario" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have used this tutorial http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ to create php - jquery - ajax
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
When i submit this form, the values just disappears from the textboxes. I like
I'm using this code to submit a form to a php script: var valid
I have three forms and using this jquery function $('form').submit(function() { $.ajax({ type: $(this).attr('method'),
I have a form as follows: <form id=myformid name=myformname method=get action=form1.php onsubmit=return checkDependant()> <fieldset>
I cant get this form to submit correctly. If I have the button type
Hi I have managed to get my form to submit without reloading, using this
A new problem emerged from this thread: jquery form validator never makes ajax call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.