SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP: Form validation not working on Firefox

    Hi everyone,

    I'm submiting a form (see the code bellow), it's works fine on IE but FIrefox doens't respect the validation and send the form anyway.

    Can someone help me?

    HTML Code:
    [HIGHLIGHT="JavaScript"]
    function validate() {
    	fnv=enviaenc.nome.value;
    	fev=enviaenc.email.value;
    	ftv=enviaenc.tel.value;
    	ffv=enviaenc.formato.value;
    	fpv=enviaenc.peso.value;
    	fqv=enviaenc.quantidade.value;
    	flv=enviaenc.local_entrega.value;
    
    	if ((fnv=='') || (fev=='') || (ftv=='') || (ffv=='') || (fpv=='') || (fqv=='') || (flv=='')) {
    	alert('Fields with * are required!');
    	return false;
    	}
    				
    	if(!enviaenc.agree.checked){
    	alert('You didn't acepted the terms, check the check box please!'); 
    	return false; 
    	} 
    }[/HIGHLIGHT]
    
    
    
    <form id="enviaenc" method="post" action="library/formmail_encomendas.php" onsubmit="validate();">
    <div style="padding-bottom:10px;">Nome*: <input type="text" tabindex="1" name="nome" size="41" class="boxform" /></div>
    <div style="padding-bottom:10px;">Telefone*: <input type="text" tabindex="2" name="tel" size="15" class="boxform" /></div>
    <div style="padding-bottom:10px;">Email*: <input type="text" tabindex="3" name="email" size="38" class="boxform" /></div>
    <div style="padding-bottom:10px;">Observações:<br /><textarea name="obs" cols="45" rows="4" tabindex="4" class="boxform" /></textarea></div>
    <div style="padding-bottom:10px;"><select name="formato" tabindex="5" class="boxform">
    	<option selected="selected"></option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	</select></div>
    <div style="padding-bottom:10px;">Peso*: <input type="text" tabindex="6" name="peso" size="3" class="boxform" />&nbsp;Kg(s)</div>
    <div style="padding-bottom:10px;">Quantidade*: <input type="text" tabindex="7" name="quantidade" size="3" class="boxform" />&nbsp;Un.(s)</div>
    <div style="padding-bottom:10px;">Estabelecimento de entrega*:<br /><select name="local_entrega" tabindex="8" class="boxform">
    	<option selected="selected"></option>
    	<option value="loja1">Loja 1</option>
    	<option value="loja2">Loja 2</option>
    	</select>
    	</div>
    	<div style="padding-bottom:20px;"><input type="checkbox" name="agree" value="sim" class="boxform" tabindex="12" />&nbsp;Li e aceito as condições de encomenda*.</div>
    	<div><input type="submit" class="box1" value="Colocar encomenda" style="border:1px solid #703801" tabindex="13" /></div>
    </form>
    

    All thanks in advance!
    .| PGAM |.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    IE is one of the only browsers that automatically creates javascript variables with the identifiers and names that are on page elements.

    For all other web browsers you will need to create those variables as and when you use them.

    For example:

    Code javascript:
    var enviaenc = document.getElementById('enviaenc');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •