...

View Full Version : Script is not friendly with FireFox and IE



darles
02-11-2007, 10:31 PM
Hi, I have problem with my javascript information checking, it works just on Opera..
<head>
<script type="text/javascript">
function vardasFunkcija() {
document.form1.vardas.disabled = ""
document.form1.slaptazodis.disabled = ""
document.form1.slaptazodis2.disabled = ""
document.form1.pastas.disabled = ""
document.form1.telefonas.disabled = ""
document.form1.adresas.disabled = ""
document.form1.miestas.disabled = ""
document.form1.taisykles.disabled = ""
}
function changeField() {
var domenas = document.forms['form1'].elements['domenas'];
var subas = document.forms['form1'].elements['sub'];
var subdomenas = document.forms['form1'].elements['subdomenas'];
if (document.form1.planai[0].checked == true) {
domenas.disabled = "disabled"
subas.disabled = ""
subdomenas.disabled = ""
} else {
domenas.disabled = ""
subas.disabled = "disabled"
subdomenas.disabled = "disabled"
}
}
</script>
<script language="javascript1.2">
function checkData() {
if (document.form1.subdomenas.value.length > "1" || document.form1.domenas.value.length > "1") {
document.form1.subdomenas.style = "";
document.form1.domenas.style = "";
document.form1.sub.style = "";
return checkVard()
}
alert("Prašome nurodyti domeną/subdomeną")
document.form1.domenas.style = "border: #FF0000 2px solid";
document.form1.subdomenas.style = "border: #FF0000 2px solid";
document.form1.sub.style = "border: #FF0000 2px solid";
return (false)
}
function checkVard() {
if (document.form1.vardas.value.length > "8") {
document.form1.vardas.style = "";
return checkSlap()
}
alert("Nurodykite vardas, pavardę.")
document.form1.vardas.style = "border: #FF0000 2px solid";
return (false)
}
function checkSlap() {
if (document.form1.slaptazodis.value.length > "5") {
document.form1.slaptazodis.style = "";
return checkSlap2()
}
alert("Įveskite slaptažodį")
document.form1.slaptazodis.style = "border: #FF0000 2px solid";
return (false)
}

function checkSlap2() {
if (document.form1.slaptazodis.value == document.form1.slaptazodis2.value) {
document.form1.slaptazodis2.style = "";
return checkTel()
}
alert("Slaptažodiai nesutampa")
document.form1.slaptazodis2.style = "border: #FF0000 2px solid";
return (false)
}

function checkTel() {
if (document.form1.telefonas.value.length == "12") {
document.form1.telefonas.style = "";
return checkEmail()
}
alert("Įveskite teisingą telefono numerį.")
document.form1.telefonas.style = "border: #FF0000 2px solid";
return (false)
}

function checkAdr() {
if (document.form1.adresas.value.length > "8") {
document.form1.adresas.style = "";
return checkMie()
}
alert("Įveskite teisingą adresą")
document.form1.adresas.style = "border: #FF0000 2px solid";
return (false)
}

function checkMie() {
if (document.form1.miestas.value.length > "3") {
document.form1.miestas.style = "";
return checkTai()
}
alert("Įveskite miestą")
document.form1.miestas.style = "border: #FF0000 2px solid";
return (false)
}

function checkTai() {
if (document.form1.taisykles.checked == true) {
document.form1.taisykles.style = "";
return (true)
}
alert("Sutikite su taisyklėmis")
document.form1.taisykles.style = "border: #FF0000 2px solid";
return (false)
}
</script>
<SCRIPT LANGUAGE="javascript1.2">
function checkEmail() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form1.pastas.value)){
document.form1.pastas.style = "";
return checkAdr()
}
alert("Įveskite teisingą el. pašto adresą.")
document.form1.pastas.style = "border: #FF0000 2px solid";
return (false)
}
</script>
</head>
<body>
<form name="form1" action="registracija.php" method="POST" onSubmit="return checkData()">
<label>
<input name="planai" type="radio" value="1" OnClick="changeField()" checked="checked" />
Subdomenas </label><br/>
<label>
<input name="planai" type="radio" value="2" OnClick="changeField()" />
Domenas </label><br/><br/>
Domenas: <input type="text" name="domenas" disabled="disabled" onChange="vardasFunkcija()"><br/>
Subdomenas: <input type="text" name="subdomenas" onChange="vardasFunkcija()"><select name="sub">
<option value=".subdomain">.subdomain</option>
<option value=".subdomain2">.subdomain2</option>
</select><br/><br/>
Vardas, Pavardė: <input type="text" name="vardas" disabled="disabled"><br/>
Slaptažodis: <input type="password" name="slaptazodis" disabled="disabled"><br/>
Slaptažodis dar kartą: <input type="password" name="slaptazodis2" disabled="disabled"><br/>
Telefonas.: <input type="text" name="telefonas" value="+3706" disabled="disabled"><br/>
El. Paštas: <input type="text" name="pastas" disabled="disabled"><br/>
Adresas: <input type="text" name="adresas" disabled="disabled"><br/>
Miestas: <input type="text" name="miestas" disabled="disabled"><br/>
Taisyklės: <input type="checkbox" name="taisykles" disabled="disabled"><br/>
Registruoti: <input type="submit" name="Registruoti" value="Registruoti" />
</form>
</body>
</html>

So how to make ir friendly for other browsers?

Arty Effem
02-12-2007, 05:29 AM
document.form1.vardas.disabled = ""
.
.
domenas.disabled = "disabled"
The way to disable an element is

element.disabled=true;
To enable an element

element.disabled=false;
Setting .disabled to an empty string could be ambiguous.

The FX JavaScript console makes the initial problem quite clear:

document.form1.domenas.style = "border: #FF0000 2px solid";

Should be:

document.form1.domenas.style.border="#FF0000 2px solid";

etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum