Ahoj,
chtel jsem dat na stranky jednoduchy objednavaci system - kdyz nekdo chce zaslat informace, musi mit povinne zadana pole jmeno, prijmeni, telefon a email (abych mel kam tomu cloveku ty informace zaslat).....
...a pokud chce zaslat informacni DVD, musi povinna pole byt take ulice, mesto a psc. ....jinak to nemuzu prede poslat postou, ze.
Programovat js moc neumim, drzel jsem se zatim u zdi podle nekterych tutorialu, ale dokud jsem nechtel tuhle podminku, vsechno fungovalo ok. (v ramci moznosti). ted si ale s tou podminkou nevim rady --- posilam kod...
Diky moc za jakoukoli pomoc....i kdyz asi kazdymu zkusenymu programatorovi asi vstavaji vlasy hruzou na hlave ...ale uz jsem zkusil tolik ruznych syntaxi, nakonec sem skoncil u tehle uplne nejtupejsi verze, ktera stejne nefunguje.
Dik Poooool
<script type="text/javascript">
function kontrola_formulare()
{
if(document.getElementById("jmeno").value.length==0) {
alert("Zadejte jmeno, je to povinný údaj.");
document.getElementById("jmeno").focus();
return false;
}
if(document.getElementById("prijmeni").value.length==0) {
alert("Zadejte prijmeni, je to povinný údaj.");
document.getElementById("prijmeni").focus();
return false;
}
if(document.getElementById("email").value.length==0) {
alert("Zadejte email, je to povinný údaj.");
document.getElementById("email").focus();
return false;
}
if(document.getElementById("telefon").value.length==0) {
alert("Zadejte telefon, je to povinný údaj.");
document.getElementById("telefon").focus();
return false;
}
if((document.getElementById("InfoDVD").value==111)&&(document.getElementById("ulice").value.length==0)) {
alert("Zadejte ulice, je to povinný údaj.");
document.getElementById("ulice").focus();
return false;
}
if((document.getElementById("InfoDVD").value==111)&&(document.getElementById("mesto").value.length==0)) {
alert("Zadejte mesto, je to povinný údaj.");
document.getElementById("mesto").focus();
return false;
}
if((document.getElementById("InfoDVD").value==111)&&(document.getElementById("psc").value.length==0)) {
alert("Zadejte PSC, je to povinný údaj.");
document.getElementById("psc").focus();
return false;
}
return true;
}
</script>
[hr]a formular
<form onSubmit="return kontrola_formulare()" action="send.php" method="post">
<table width="" border="0">
<tr>
<td width="33">Jméno*:</td>
<td width="40"><input name="jmeno" id="jmeno" type="text"></td>
</tr>
<tr>
<td width="33">Příjmení*:</td>
<td width="40"><input name="prijmeni" id="prijmeni" type="text"></td>
</tr>
<tr>
<td width="33">Email*:</td>
<td width="40"><input name="email" id="email" type="text"></td>
</tr>
<tr>
<td width="33">Telefon*:</td>
<td width="40"><input name="telefon" id="telefon" type="text"></td>
</tr>
<tr>
<td width="33">Zpráva:</td>
<td colspan="4" class="input">
<textarea rows="2" name="zprava" id="zprava" cols="40" class="text" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
Přejete si objednat informační DVD? <input name="InfoDVD" type="checkbox" value="111" id="InfoDVD" />
Ano
</td>
</tr>
<td colspan="2" >
Pokud budete objednávat informační DVD, je třeba zadat doručovací adresu
</td>
<tr>
<td width="33">Ulice</td>
<td width="40"><input name="ulice" id="ulice" type="text"></td>
</tr>
<tr>
<td width="33">Město</td>
<td width="40"><input name="mesto" id="mesto" type="text"></td>
</tr>
<tr>
<td width="33">PSČ</td>
<td width="40"><input name="psc" id="psc" type="text"></td>
</tr>
<td colspan="2" align="center">
<input type="submit" class="" value="Odeslat">
<input type="reset" class="button" value="Vymazat"></td>
</tr>
<tr>
<td width="33"></td>
<td width="80"><font size="0.75em">* povinny udaj</font></td>
</tr>
</table>
</form>
Fórum › JavaScript, AJAX, jQuery
Kontrola pole ve formulari - s podminkou ...?

Diky moc. funguje to.
dalsim krokem bude zjistovani, zda telefon je opravdu cislo, nebo zda email je opravdu obsahuje spravny format s @ atp, ale na to snad zase nekde sezenu dobry tutorialy na webu. kdyby jste meli nejaky dobry odkaz, budu vdecen jeste vic :)
Poooool

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 21 hostů
Podobná vlákna
Kontrola emailu ve formuláři — založil cheeester
Kontrola věcí ve formuláři a nejen to! — založil
Kontrola pole — založil Paja2
Problém s podminkou — založil Coal_Asasin
Potíže s podmínkou — založil almashi
Moderátoři diskuze