• Home
  • Forum
  • Fare Web
  • Javascript

File esterni JS

  • Creatore Discussione Creatore Discussione luigi777
  • Data di inizio Data di inizio 21 Apr 2012
  • Tag Tag
    form javascript
L

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
  • 21 Apr 2012
  • #1
Salve, io non so il motivo come mai se metto le funzioni per controllare il form in un file esterno .. non funzionano come mai?
vi posto i codici:

utenti.js:
PHP:
function CheckForm_modifica(form){
		//Avvio il controllo dei campi
		var booReturn = true;
		//strMessage
		var strMessage = "Attenzione, compilare i seguenti campi:\n"
		if(form.strNome.value == ""){
			strMessage += "*strNome\n";
			booReturn = false;
		}
		if(form.strCognome.value == ""){
			strMessage += "*strCognome\n";
			booReturn = false;
		}
		if(form.strCompleanno.value == ""){
			strMessage += "*strCompleanno\n";
			booReturn = false;
		}
		
		
		//Controllo
		if(form.strUser.value == ""){
			strMessage += "*strUser\n";
			booReturn = false;
		}
	
		if(form.strPass.value == ""){
			strMessage += "*strPass\n";
			booReturn = false;
		}
		if(form.strData.value == ""){
			strMessage += "*strData\n";
			booReturn = false;
		}
	if(form.strEmail.value == ""){
			strMessage += "*strEmail\n";
			booReturn = false;
		}
		
		//Ritorno booReturn
		if(booReturn == false){
			alert (strMessage);
		}
		return booReturn;
	}
	
function CheckForm_aggiungi(form){
		//Avvio il controllo dei campi
		var booReturn = true;
		//strMessage
		var strMessage = "Attenzione, compilare i seguenti campi:\n"
		
		//Controllo
		if(form.strUser.value == ""){
			strMessage += "*strUser\n";
			booReturn = false;
		}if(form.strNome.value == ""){
			strMessage += "*strNome\n";
			booReturn = false;
		}
		if(form.strCognome.value == ""){
			strMessage += "*strCognome\n";
			booReturn = false;
		}
		if(form.strCompleanno.value == ""){
			strMessage += "*strCompleanno\n";
			booReturn = false;
		}
		
		if(form.strSesso.checked){
			strMessage += "*strSesso\n";
			booReturn = true;
		}
		if(form.strLevel.checked){
			strMessage += "*strLevel\n";
			booReturn = true;
		}
		if(form.strPass.value == ""){
			strMessage += "*strPass\n";
			booReturn = false;
		}
		if(form.strData.value == ""){
			strMessage += "*strData\n";
			booReturn = false;
		}
	if(form.strEmail.value == ""){
			strMessage += "*strEmail\n";
			booReturn = false;
		}
		
		//Ritorno booReturn
		if(booReturn == false){
			alert (strMessage);
		}
		return booReturn;
	}

e nel file che mi interessa dove ci sono i form dove devo controllare .. ho messo questo codice in prima riga del file utenti.php.
Codice:
<script type="text/javascript" src="utenti.js"></script>

come mai?

il form lo chiamo cosi:
Codice:
<form method="post" action="index.php?m=utenti&action=aggiungi" onsubmit="return CheckForm_aggiungi(form);">

mi date informazioni come fare?

Devo fare solo il controlli via javascript che poi ho finito il mio sito .. solo che mi servono quelli lato client..quelli lato server lo già fatti.

Ciao e grazie e buon sabato.
 
N

Nefyt

Utente Attivo
17 Apr 2012
1.102
0
0
  • 21 Apr 2012
  • #2
Senza includerlo in un file esterno andava? (In modo da escludere problemi nella funzione)

Prova a chiamarla cosi:
Codice:
return CheckForm_aggiungi(this);

Edit: hai dato il nome a tutti gli elementi del form ovviamente?
 
Ultima modifica: 21 Apr 2012
L

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
  • 21 Apr 2012
  • #3
Nefyt ha scritto:
Senza includerlo in un file esterno andava? (In modo da escludere problemi nella funzione)

Prova a chiamarla cosi:
Codice:
return CheckForm_aggiungi(this.form);
Clicca per allargare...
si.. non funziona nemmeno cosi, .. invece inclusa nella form funzionava solo che vorrei separare l'html dal codice ed usare il javasript con file esterni..

praticamente è quello che avevo postato quell'altro giorno "Tutti i campi obbligatori"..

ma mettendolo nel file js non funziona..

come posso fare grazie mille e buona serata.
 
L

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
  • 21 Apr 2012
  • #4
si..dici che devo dare anche gli id="strNome"??

non è che sbaglio a validare qualche campo ed il javascript non funziona?



questo è il form:
PHP:
	<h1>Aggiungi Utenti</h1>
	<form method="post" action="index.php?m=utenti&action=aggiungi" name="form" onsubmit="return CheckForm_aggiungi(this);">
	     <table width="100%" border="1" cellspacing="2" cellpadding="2">
         <tr>
         <td width="22%">strNome</td>
         <td width="78%"><input type="text" name="strNome"  value="<?php echo @$strNome;?>" size="20" maxlength="100" /></td>
       </tr>
	     <tr>
         <td width="22%">strCognome</td>
         <td width="78%"><input type="text" name="strCognome" value="<?php echo @$strCognome;?>" size="20" maxlength="100" /></td>
       </tr>
	   <tr>
         <td>Sesso</td>
         <td><label>
           <input type="radio" name="strSesso" value="1" <?php if($strSesso=='1') echo 'checked="checked"'?> />
           Maschio</label>
           <label>
             <input type="radio" name="strSesso" value="2" <?php if($strSesso=='2') echo 'checked="checked"'?>/>
            Femmina </label>
           </td>
		   <tr>
         <td width="22%">strCompleanno</td>
         <td width="78%"><input type="text" name="strCompleanno" value="<?php echo @$strCompleanno;?>" size="20" maxlength="100" /></td>
       </tr>
	   <tr>
         <td width="22%">strUser</td>
         <td width="78%"><input type="text" name="strUser" value="<?php echo @$strUser;?>" size="20" maxlength="100" /></td>
       </tr>
       <tr>
         <td>strEmail</td>
         <td><input type="text" name="strEmail" value="<?php echo @$strEmail;?>" size="50" maxlength="100" /></td>
       </tr>
       <tr>
         <td>strPass</td>
         <td><input type="text" name="strPass" value="<?php echo @$strPass;?>" size="50" maxlength="100" /></td>
       </tr>
       <tr>
         <td>strData</td>
         <td><input type="text" name="strData" value="<?php echo date("d-m-Y")?>" size="50" maxlength="100" /></td>
       </tr>
       <tr>
         <td>Livello Utente</td>
         <td><label>
           <input type="radio" name="strLevel" value="1" <?php if($strLevel=='1') echo 'checked="checked"'?> />
           Amministratore</label>
           <label>
             <input type="radio" name="strLevel" value="2" <?php if($strLevel=='2') echo 'checked="checked"'?>/>
             Moderatore </label>
           <label>
             <input type="radio" name="strLevel" value="3" <?php if($strLevel=='3') echo 'checked="checked"'?>/>
         Utente</label></td>
       </tr>
       <tr>
         <td>Stato</td>
         <td><label>
           <input type="radio" name="strStato" value="1" <?php if($strStato=='1') echo 'checked="checked"'?> />
           Pubblica</label>
           <label>
             <input type="radio" name="strStato" value="2" <?php if($strStato=='2') echo 'checked="checked"'?>/>
         Nascondi</label></td>
       </tr>
       <tr>
         <td>&nbsp;</td>
         <td><input type="submit" name="submit" value="Inserisci login" />           <input type="reset" value="Annulla Modifiche" /></td>
       </tr>
       <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
       </tr>
     </table>
	</form>
 
N

Nefyt

Utente Attivo
17 Apr 2012
1.102
0
0
  • 21 Apr 2012
  • #5
Vedo che hai dato un nome al form prova a chiamarla cosi return CheckForm_aggiungi('form');
e poi metti il ; alla fine degli shortif in php
 
L

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
  • 21 Apr 2012
  • #6
Nefyt ha scritto:
Vedo che hai dato un nome al form prova a chiamarla cosi return CheckForm_aggiungi('form');
e poi metti il ; alla fine degli shortif in php
Clicca per allargare...

scusa, ma ho risolto era il file js che non caricava perché sbagliavo percorso..

ti ringrazio molto..alla prossima..
 
Devi accedere o registrarti per poter rispondere.

Discussioni simili

P
Javascript su file esterni
  • Paolo123
  • 23 Dic 2017
  • Javascript
Risposte
2
Visite
1K
Javascript 23 Dic 2017
Paolo123
P
N
[Access 2007] Come esportate risultati query in file esterni?
  • nikkysixx
  • 20 Dic 2009
  • MS Access
Risposte
0
Visite
2K
MS Access 20 Dic 2009
nikkysixx
N
G
caricare file midi esterni tramite javascript inserito nella pagina html generata con
  • giulien
  • 4 Set 2004
  • Flash
Risposte
0
Visite
2K
Flash 4 Set 2004
giulien
G
G
problema bordo trasparente file
  • GIULIA CERRY
  • 20 Giu 2025
  • Photoshop
Risposte
1
Visite
116
Photoshop 20 Giu 2025
GIULIA CERRY
G
S
incollare file PNG su Photoshop
  • Stefanowls
  • 26 Mar 2025
  • Photoshop
Risposte
2
Visite
183
Photoshop 26 Mar 2025
Stefanowls
S
F
errore file creato con ps 2025
  • fabry1707
  • 22 Mar 2025
  • Photoshop
Risposte
0
Visite
173
Photoshop 22 Mar 2025
fabry1707
F
L
file pdf e database
  • lorenzo@1@
  • 17 Mag 2024
  • PHP
Risposte
2
Visite
1K
PHP 23 Mag 2024
lorenzo@1@
L
E
fpdf salvare e aprire il file
  • Emanuele85
  • 11 Mar 2024
  • PHP
Risposte
4
Visite
2K
PHP 14 Mar 2024
Emanuele85
E
I
asp | includere un file, indirizzo depositato in un db
  • IvanID
  • 9 Feb 2024
  • Classic ASP
Risposte
1
Visite
4K
Classic ASP 30 Mag 2025
Paolo69
[Windows 10] Scompare icone, file e collegamenti sul desktop
  • felino
  • 8 Feb 2024
  • Windows e Software
Risposte
0
Visite
2K
Windows e Software 8 Feb 2024
felino
S
passare un valore da un form a un file .php con metodo post
  • smack2005
  • 15 Nov 2023
  • PHP
Risposte
4
Visite
1K
PHP 23 Nov 2023
zorro
D
Miglior modo per estrarre le occorrenze di un elemento in un set di più file xml e quindi scrivere il risultato in una tabella Excel o magari in JSON
  • dario_s
  • 23 Ott 2023
  • XML
Risposte
0
Visite
3K
XML 23 Ott 2023
dario_s
D
G
file CSS contenente variabili
  • Gae
  • 29 Ago 2023
  • HTML e CSS
Risposte
1
Visite
2K
HTML e CSS 14 Gen 2024
Alex Mercer
A
M
Creare traccia di download file sul server
  • Morgy
  • 29 Lug 2023
  • HTML e CSS
Risposte
2
Visite
2K
HTML e CSS 14 Ago 2023
Morgy
M
I
elimina file
  • Imperor
  • 29 Apr 2023
  • PHP
Risposte
1
Visite
942
PHP 18 Lug 2023
alankanz
I
cerca file sottocartella unlink file
  • Imperor
  • 28 Apr 2023
  • PHP
Risposte
0
Visite
603
PHP 28 Apr 2023
Imperor
I
I
sessione username scarica file
  • Imperor
  • 19 Apr 2023
  • PHP
Risposte
1
Visite
919
PHP 20 Apr 2023
Imperor
I
S
Aggiornare percorso file collegati
  • Silverado60
  • 18 Apr 2023
  • MS Access
Risposte
0
Visite
1K
MS Access 18 Apr 2023
Silverado60
S
I
lista file sottocartella elimina file
  • Imperor
  • 13 Apr 2023
  • PHP
Risposte
3
Visite
1K
PHP 18 Lug 2023
alankanz
F
comando di inclusione file audio in I-Pad non funziona
  • francescoschino
  • 10 Apr 2023
  • HTML e CSS
Risposte
1
Visite
1K
HTML e CSS 14 Gen 2024
Alex Mercer
A
Condividi:
Facebook X (Twitter) LinkedIn WhatsApp e-mail Condividi Link
  • Home
  • Forum
  • Fare Web
  • Javascript
  • Italiano
  • Termini e condizioni d'uso del sito
  • Policy Privacy
  • Aiuto
  • Home
Community platform by XenForo® © 2010-2024 XenForo Ltd. | Traduzione a cura di XenForo Italia
Menu
Accedi

Registrati

  • Home
  • Forum
    • Nuovi Messaggi
    • Cerca...
  • Novità
    • Featured content
    • Nuovi Messaggi
    • Ultime Attività
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?