Form problem??

K

kec

I want to create a script that prevent users of my form for typeing stupid
things.
Here is my script:
<script language="JavaScript" type="text/JavaScript">
<!--
function provjera(s1, s2, s3, s4) {
var ime1 = document.formular.ime;
var email1 = document.formular.email;
var mob1 = document.formular.mob;
var izbornik1 = document.formular.izbornik;
var obj1 = document.getElementById("s1");
var obj2 = document.getElementById("s2");
var obj3 = document.getElementById("s3");
var obj4 = document.getElementById("s4");

if (ime1.value.indexOf(" ") == -1) {
obj1.style.display = "block";
ime1.focus();
}
else obj1.style.display = "none";
if ((email1.value.indexOf("@") == -1) || (email1.value.indexOf(".") == -1))
{
obj2.style.display = "block";
email1.focus();
}
else obj2.style.display = "none";
if (mob1.length == 0) {
obj3.style.display = "block";
mob1.focus();
}
else obj3.style.display = "none";
if (izbornik1.selectedIndex == 0) {
obj4.style.display = "block";
izbornik1.focus();
} else {
obj4.style.display = "none";
document.formular.submit(); // Kaze da u ovom redu nesto ne valja
}
}
//-->
</script>

In Firefox it is good but Internet Explorer always want to debug.
He seys:
Line: 62
Error:Object doesn't support this property or method




Please Help m!!!!!


How I fix this??????????
 
M

Mikhail Esteves

kec said:
I want to create a script that prevent users of my form for typeing stupid
things.

What kind of input are you trying to validate? If its only to block
weird characters from an ordinary textbox, why not use a Regular
Expression instead?

function IsLegal(str){
// Checks for @ ( ) < > [ ] , ; : \ / "
var badchars = /[\@\(\)\<\>\,\;\:\\\/\"\[\]]/
if (str.match(badchars))
return false;
else
return true;
}

if (!IsLegal(Form.TextBox.Text))
{
alert("Illegal characters in TextBox. Please try again!");
}

HTH.

Mikhail
 
K

kec

Form:
<form name="formular"action="kontakti2.php" method="post">
<table width="477" border="0">
<tr>
<td colspan="2"><div align="center">
<p><strong>Obrazac za kontakt </strong></p>
<p>&nbsp;</p>
</div></td>
</tr>
<tr>
<td width="213" rowspan="2">Vase ime i prezime: </td>
<td width="248"><p align="left">
<input name="ime" type="text" size="41"></p>

</td>
</tr>
<tr>
<td><div style=" color:#FF0000; display:none" id="s1">Upisite svoje ime
i prezime.</div></td>
</tr>
<tr>
<td>Vasa email adresa:</td>
<td><p>
<input name="email" type="text" size="41">
</p>
<div id="s2" style="display:none; color:#FF0000 ">Upisite svoju pravu
email adresu. </div></td>
</tr>
<tr>
<td>Broj telefona ili mobitela:</td>
<td><p>
<input name="mob" type="text" id="mob2" size="41">
</p>
<div id="s3" style=" color:#FF0000; display:none ">Upisite vas broj
telefona ili mobitela. </div></td>
</tr>
<tr>
<td>Poduzece:</td>
<td><p>
<input name="firma" type="text" id="firma" size="41">
</p>
<p style=" color:#FF0000; display:none ">Skojom firmom kontaktiramo
</p></td>
</tr>
<tr>
<td>Kako zelite da vas kontaktiramo:</td>
<td><p>
<select name="izbornik">
<option>= Odaberite =</option>
<option value="Telefonom_ili mobitelom">Tel. / Mob.</option>
<option value="Emailom">Emailom</option>
</select>
</p>
<div id="s4" style="display:none; color:#FF0000 ">Kako da vas
kontaktiramo? </div></td>
</tr>
<tr>
</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="submit" type="submit"
value="Salji!" onClick="provjera(s1, s3, s2, s3, s4); return false;"></td>
</tr>

</table>
</form>

Script:
<script language="JavaScript" type="text/JavaScript">
<!--
function provjera(s1, s2, s3, s4) {
var ime1 = document.formular.ime; //
var email1 = document.formular.email;
var mob1 = document.formular.mob;
var izbornik1 = document.formular.izbornik;
var obj1 = document.getElementById("s1");
var obj2 = document.getElementById("s2");
var obj3 = document.getElementById("s3");
var obj4 = document.getElementById("s4");

if (ime1.value.indexOf(" ") == -1) {
obj1.style.display = "block";
ime1.focus();
}
else obj1.style.display = "none";
if ((email1.value.indexOf("@") == -1) || (email1.value.indexOf(".") == -1))
{
obj2.style.display = "block";
email1.focus();
}
else obj2.style.display = "none";
if (mob1.length == 0) {
obj3.style.display = "block";
mob1.focus();
}
else obj3.style.display = "none";
if (izbornik1.selectedIndex == 0) {
obj4.style.display = "block";
izbornik1.focus();
} else {
obj4.style.display = "none";
document.formular.submit(); // Kaze da u ovom redu nesto ne valja
}
}
//-->
</script>
Mikhail Esteves said:
kec said:
I want to create a script that prevent users of my form for typeing
stupid
things.

What kind of input are you trying to validate? If its only to block
weird characters from an ordinary textbox, why not use a Regular
Expression instead?

function IsLegal(str){
// Checks for @ ( ) < > [ ] , ; : \ / "
var badchars = /[\@\(\)\<\>\,\;\:\\\/\"\[\]]/
if (str.match(badchars))
return false;
else
return true;
}

if (!IsLegal(Form.TextBox.Text))
{
alert("Illegal characters in TextBox. Please try again!");
}

HTH.

Mikhail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top