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

  • SEARCH
  • Home
  • 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 1063133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:19+00:00 2026-05-16T18:44:19+00:00

I wrote simple custom validation on javascript based on this doc . I want

  • 0

I wrote simple custom validation on javascript based on this doc. I want it to display an alert if a select has been chosen on “Si” and the text fields are left blank. I don’t get why it isn’t displaying the message.

<html> 
<head>


<link rel="stylesheet" type="text/css" media="screen" href="mistylesheet.css"/>

<script type ='text/javascript'>

function mivalidate (elem1, elem2, elem3, elem4) {


     if(elem1.value=="Si")&&(elem2.value.length==0)&&( (elem3.value.length==0)||(elem4.value.length==0)){

        alert("Por favor, especifique un nombre y un email o tel&eacute;fono de contacto en su recomendaci&oacute;n ");
        elem1.focus();
        return false;
      } else {

        return true;
    }


}



</script>

</head>
<body>
<form onsubmit='return mivalidate(document.getElementById("recomiendaONo"),document.getElementById("nombreRecomendado"), document.getElementById("emailRecomendado"), 
 document.getElementById("telefonoRecomendado"))'>

     <table class="layouttable">

        <tr class='row1'><td> <b>&#191;Recomendar&iacute;a nuestros servicios a otra empresa o persona?  </b></td></tr>
        <tr class='row2'><td> 



        <select id = "recomiendaONo" name="recomiendaONo" class="required">
           <option value="">Seleccione su respuesta</option>
             <option value="Si">S&iacute;</option>
         <option value="No">No</option>

        </select>



        </td></tr>


  </table>    






<div class='margenrecomendaciones'>
<table>

<tbody>


<tr>



<td><div align="left">Nombre:</div></td> 

<td><div align="left"><input class="texto" id="nombreRecomendado" name="nombreRecomendado" type="text" size="30"/></div></td>

</tr>      




<td><div align="left">Email:</div></td>

<td><div align="left"> <input  class="texto" id="emailRecomendado" name="emailRecomendado" type="text" size="30"/></div></td>




</tr>

<tr>



<td><div align="left">Tel&eacute;fono:</div></td>

<td><div align="left"> <input class=" texto" name="telefonoRecomendado" id="telefonoRecomendado" type="text" size="30"/></div></td>




</tr>


</tbody>

</table>
</div>

    <input type="submit"/>


</form>
</body>
</html>
  • 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-16T18:44:19+00:00Added an answer on May 16, 2026 at 6:44 pm

    You need to wrap your entire if statement in parentheses.

    This:

    if (elem1.value == "Si") && (elem2.value.length == 0) && ((elem3.value.length == 0) || (elem4.value.length == 0))
    

    should be:

    if ((elem1.value == "Si") && (elem2.value.length == 0) && ((elem3.value.length == 0) || elem4.value.length == 0)))
    

    (I also added spaces around the operators and after the if to make everything more clear and readable, and you should as well. Also, using a text editor or IDE that shows matching braces really helps keep track of them.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple game and I want to add custom pointer. I created
I just wrote a simple DirectShow Filter (which inherits from CTransformFilter). But I want
I just want to use developer app for creating normal simple custom tab. And
I wrote a very simple plugin to add custom fields to media library but
I wrote a Simple Control, that implements ScriptControl. This is holder for JQuery framework:
Well this should've been simple enough. I modified the project's web.xml in order to
I am trying to write a simple Wordpress plugin, which updates a custom field
I created a custom view that uses Json.Simple to serialize the model and write
i wrote simple 3 functions to scrape titles , description and keywords of simple
I wrote simple class that on the start it just increase the value of

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.