By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,960 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,960 IT Pros & Developers. It's quick & easy.

Form problem??

P: n/a
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??????????
Sep 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
kec wrote:
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

Sep 14 '05 #2

P: n/a
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>
<td height="43">Vasa poruka:</td>
<td height="43"><textarea rows="5" cols="37" name="poruka"
</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" <mi*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... kec wrote:
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

Sep 14 '05 #3

P: n/a
Mikhail,

Your "badchars" are:

[ @ ( ) < > , ; : \ / " ]

Is that right?

Sep 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.