04. august 2003 - 12:07Der er
18 kommentarer og 1 løsning
hvorfor stopper IF-sætningen?
Luk annonce Hej Eksperter,
Når jeg udfører denne script så checker den kun "nickname" og ikke andet. det er som om scriptet bare stopper...
Hvorfor?
<script> function validate(check) { if(check.nickname.value=="") { alert("Please enter your desired Nickname"); check.nickname.focus(); return(false); }
if(check.firstname.value=="") { alert("Please enter your Name"); check.firstname.focus(); return(false); }
if(check.lastname.value=="") { alert("Please enter your desired Last Name"); check.lastname.focus(); return(false); } if(check.email.value=="") { alert("Please enter your E-mail"); check.email.focus(); return(false); } if(check.address.value=="") { alert("Please enter your Address"); check.address.focus(); return(false); } if(check.age.value=="") { alert("Please enter your Age"); check.age.focus(); return(false); }
if (check.password1.value == "") { alert("you must enter a password"); check.password1.focus(); return (false); } if (check.password1.value != check.password2.value) { alert("Entered passwords did not match"); check.password1.focus(); check.password1.select(); return (false); } return (true);
som iver25 siger du ber den løbende om at returne false, og det breaker scriptet!
en hurtig omskrivning kunne se sådan ud!
<script> function validate(check) str = "Problems with following fields\n\n"
{ if(check.nickname.value=="") { str =+ "Please enter your desired Nickname\n"; v = false }
if(check.firstname.value=="") { str =+ "Please enter your Name\n"; v = false }
if(check.lastname.value=="") { str =+ "Please enter your desired Last Name\n"; v = false } if(check.email.value=="") { str =+ "Please enter your E-mail\n"; v = false } if(check.address.value=="") { str =+ "Please enter your Address\n"; v = false } if(check.age.value=="") { str =+ "Please enter your Age\n"; v = false }
if (check.password1.value == "") { str =+ "you must enter a password\n"; v = false } if (check.password1.value != check.password2.value) { str =+ "Entered passwords did not match\n"; check.password1.focus(); check.password1.select(); v = false }
hovsa - når jeg bruger grunkens kode så siger den at der r fejl. Jeg har prøvet at rette den igennem - men kan ikke se hvor fejlen skulle ligge...
<script> function validate(check) str = "Problems with following fields\n\n"
{ if(check.nickname.value=="") { str += "Please enter your desired Nickname\n"; v = false }
if(check.firstname.value=="") { str += "Please enter your Name\n"; v = false }
if(check.lastname.value=="") { str += "Please enter your desired Last Name\n"; v = false } if(check.email.value=="") { str += "Please enter your E-mail\n"; v = false } if(check.address.value=="") { str += "Please enter your Address\n"; v = false } if(check.age.value=="") { str += "Please enter your Age\n"; v = false }
if (check.password1.value == "") { str += "you must enter a password\n"; v = false } if (check.password1.value != check.password2.value) { str += "Entered passwords did not match\n"; check.password1.focus(); check.password1.select(); v = false }
snøft det virker stadig ikke, måske skulle jeg bare holde nallerne fra :o(
<script> function validate(check){ str = "Problems with following fields\n\n"
if(check.nickname.value=="") { str += "Please enter your desired Nickname\n"; v = false }
if(check.firstname.value=="") { str += "Please enter your Name\n"; v = false }
if(check.lastname.value=="") { str += "Please enter your desired Last Name\n"; v = false } if(check.email.value=="") { str += "Please enter your E-mail\n"; v = false } if(check.address.value=="") { str += "Please enter your Address\n"; v = false } if(check.age.value=="") { str += "Please enter your Age\n"; v = false }
if (check.password1.value == "") { str += "you must enter a password\n"; v = false } if (check.password1.value != check.password2.value) { str += "Entered passwords did not match\n"; check.password1.focus(); check.password1.select(); v = false }
<script> function validate(check){ str = "Problems with following fields\n\n"
if(check.nickname.value=="") { str += "Please enter your desired Nickname\n"; v = false }
if(check.firstname.value=="") { str += "Please enter your Name\n"; v = false }
if(check.lastname.value=="") { str += "Please enter your desired Last Name\n"; v = false } if(check.email.value=="") { str += "Please enter your E-mail\n"; v = false } if(check.address.value=="") { str += "Please enter your Address\n"; v = false } if(check.age.value=="") { str += "Please enter your Age\n"; v = false }
if (check.password1.value == "") { str += "you must enter a password\n"; v = false } if (check.password1.value != check.password2.value) { str += "Entered passwords did not match\n"; check.password1.focus(); check.password1.select(); v = false }
if(v != false){ v=true;} else{ alert(str);}
return v
} </script>
<form method="post" action="Mforum_newuser2.asp" name="form" onsubmit="return validate(this)" > <title>Add new user</title>
<h2>Add new user</h2> <br> <p>Form vil not create user unless all fields are filled out !</p> <table> <tr> <td>Nickname:</td> <td><input name="nickname"></td> </tr><tr> <td>E-mail:</td> <td><input name="email"></td> </tr><tr> <td>First Name:</td> <td><input name="FirstName"></td> </tr><tr> <td>Last Name:</td> <td><input name="LastName"></td> </tr><tr> <td>Type password:</td> <td><input type="PASSWORD" name="password1" value=""></td> </tr><tr> <td>Verify password:</td> <td><input type="PASSWORD" name="password2" value=""></td> </tr><tr> <td>Address:</td> <td><input name="Address"></td> </tr><tr> <td><input name="Date" type="hidden" value="<% Response.write Date() %>"></td> </tr><tr>
nå men, sådan ser hele lortet ud (med undtagelse af connection password ;o)) Men det har ikke hjulpet en skid. Var vist lige hurtig nok til at afgive points der...
Synes godt om
Slettet bruger
06. august 2003 - 15:23#14
JavaScript tager højde for store og små bogstaver, så hvis du kalder et felt for "LastName", skal der ikke stå "lastname" i scriptet.
I øvrigt vil et link være meget mere behjælpeligt. For det første, fordi ASP-koden er ligegyldig for os JavaScriptere, og for det andet fordi man så selv kan se de fejl, der fremkommer.
jeg har løst problemet... Der var altså ikke noget galt med den oprindelige kode. Problemet var som phoenixv sagde - jeg skal huske at JavaScripts er case-sensetive. Ligeså snart jeg rettededet i den originale kode, så virkede det. Rettede jeg derimod det samme i den kode der blev foreslået i eksperten, så virkede det ikke...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.