News:

Go to HostNed.com
Welcome.  This is a place to get user-to-user support, learn more, and share ideas.  If you can't find your answers here, feel free to ask by creating a new topic or visit the support ticket system at https://my.hostned.com :)  Have fun here!

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - giovas

#1
Scripting / Re: [How To] Making a form field required
February 12, 2009, 06:33:03 PM
Hi, this doesn't seem to work for me. I must be missing something...... Here is the validation code:



<script>
function ValidateContacto)
{
    var nombre = document.Contacto.Nombre;
var apellidoPaterno = document.Contacto.ApellidoPaterno;
    var email = document.Contacto.Email;
var ciudad = document.Contacto.Ciudad;
var estado = document.Contacto.Estado;
var pais = document.Contacto.Pais;

    if (email.value == "")
    {
        window.alert("Por favor escriba su dirección de E-Mail.");
        email.focus();
        return false;
    }
    if (Email.value.indexOf("@", 0) < 0)
    {
        window.alert("Por favor vuelva revise que su dirección de E-Mail este escrita correctamente.");
        Email.focus();
        return false;
    }
    if (Email.value.indexOf(".", 0) < 0)
    {
        window.alert("Por favor vuelva revise que su dirección de E-Mail este escrita correctamente.");
        Email.focus();
        return false;
    }
    if (Nombre.value == "")
    {
        window.alert("Por favor escriba su Nombre.");
        Nombre.focus();
        return false;
    }
    if (ApellidoPaterno.value == "")
    {
        window.alert("Por favor escriba su Apellido Paterno.");
        ApellidoPaterno.focus();
        return false;
    }
    if (Ciudad.value == "")
    {
        window.alert("Por favor escriba su Ciudad.");
        Ciudad.focus();
        return false;
    }
    if (Estado.value == "")
    {
        window.alert("Por favor escriba su Estado.");
        Estado.focus();
        return false;
    }
    if (Pais.value == "")
    {
        window.alert("Por favor escriba su Pais.");
        Pais.focus();
        return false;
    }
    return true;
}
</script>



And this is the form code:



<form action="sendmail.php" method="post" name="Contacto" id="Contacto" onsubmit="return ValidateContacto();">
          <table width="91%" border="0">
            <tr>
              <td width="29%" class="style1"><div align="right">Deseo:</div></td>
              <td width="71%" class="style1"><label>
                <input name="InfoDiagPrec" type="checkbox" class="style1" id="InfoDiagPrec" />
                Recibir más información sobre lo que puedo hacer en <span class="style7">D</span><span class="style19">iag</span><span class="style7">P</span><span class="style19">rec</span></label></td>
            </tr>
            <tr>
              <td class="style1">&nbsp;</td>
              <td class="style1"><input name="InfoMembresias" type="checkbox" class="style1" id="InfoMembresias" />
Recibir más información sobre las membresias</td>
            </tr>
            <tr>
              <td class="style1"><div align="right"></div></td>
              <td class="style1"><input name="Contratar" type="checkbox" class="style1" id="Contratar" />
                Contratar</td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Nombre:</div></td>
              <td class="style1"><label>
                <input name="Nombre" type="text" class="style1" id="Nombre" />
                <span class="style20">*</span>              </label></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Apellido Paterno:</div></td>
              <td class="style1"><input name="ApellidoPaterno" type="text" class="style1" id="ApellidoPaterno" /> <span class="style20">*</span></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Apellido Materno:</div></td>
              <td class="style1"><input name="ApellidoMaterno" type="text" class="style1" id="ApellidoMaterno" /></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">E-Mail:</div></td>
              <td class="style1"><input name="Email" type="text" class="style1" id="Email" /> <span class="style20">*</span></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Teléfono:</div></td>
              <td class="style1"><input name="Lada1" type="text" class="style1" id="Lada1" size="3" maxlength="3" />
                -
                <input name="Lada2" type="text" class="style1" id="Lada2" size="3" maxlength="3" />
                -
                <input name="Telefono" type="text" class="style1" id="Telefono" size="8" maxlength="8" /></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Celular:</div></td>
              <td class="style1"><input name="Lada3" type="text" class="style1" id="Lada3" size="3" maxlength="3" />
                -
                <input name="Lada4" type="text" class="style1" id="Lada4" size="3" maxlength="3" />
                -
                <input name="Celular" type="text" class="style1" id="Celular" size="8" maxlength="8" /></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Ciudad:</div></td>
              <td class="style1"><input name="Ciudad" type="text" class="style1" id="Ciudad" /> <span class="style20">*</span></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">Estado:</div></td>
              <td class="style1"><input name="Estado" type="text" class="style1" id="Estado" /> <span class="style20">*</span></td>
            </tr>
            <tr>
              <td class="style1"><div align="right">País:</div></td>
              <td class="style1"><input name="Pais" type="text" class="style1" id="Pais" /> <span class="style20">*</span></td>
            </tr>
            <tr>
              <td valign="top" class="style1"><div align="right">Comentarios:</div></td>
              <td class="style1"><label>
                <textarea name="Comentarios" cols="45" rows="5" class="style1" id="Comentarios"></textarea>
              </label></td>
            </tr>
            <tr>
              <td class="style1"><span class="style20">*Campo Obligatorio</span></td>
              <td class="style1">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="2" align="center" class="style1"><label>
                <input type="submit" name="button" id="button" value="Enviar" />
              </label></td>
            </tr>
          </table>
        </form>