LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2003, 11:43 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Javascript error


The alert message never activated when at least one of the ip field is blank. There was a message on the bottom left hand side that sid "error on page"

==================================
Code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--

function check_for_blank_in_ip()
{
   if ((ip1 <>""  && ip2 <>""  && ip3 <>""  && ip4 ==""))  || 
       (ip1 <>""  && ip2 <>""  && ip3 ==""  && ip4 <>"" )  || 
       (ip1 <>""  && ip2 ==""  && ip3 <>""  && ip4 <>"" )  || 
       (ip1 ==""  && ip2 <>""  && ip3 <>""  && ip4 <>"" )  ||
       (ip1 <>""  && ip2 <>""  && ip3 ==""  && ip4 =="" )  ||
       (ip1 ==""  && ip2 <>""  && ip3 <>""  && ip4 =="" ))
     alert ("All four IP values must be filled in"); 
}
    
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
   <input type=text size=3 maxlength=3 name=ip1 onblur='check_for_blank_in_ip();'><b>.</b>
   <input type=text size=3 maxlength=3 name=ip2 onblur='check_for_blank_in_ip();'><b>.</b>
   <input type=text size=3 maxlength=3 name=ip3 onblur='check_for_blank_in_ip();'><b>.</b>
   <input type=text size=3 maxlength=3 name=ip4 onblur='check_for_blank_in_ip();'>&nbsp;</td>
</form>

</body>
</html>
 
Old 09-26-2003, 12:09 PM   #2
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
well first it might be cleaner to say

if (ip1 == "" || ip2 == "" || ip3 == "" || ip4 == "")
alert ('fill in your IP');

second I would try an alert before the 'if' to see what values your ip1-4 does have ... (make sure you're referencing what you think your referencing)

alert ('ip1 is '+ip1+' and ip2 is '+ip2);
alert ('ip3 is '+ip3+' and ip4 is '+ip4);

if (ip1 == "" ...

also I think in Java (maybe <> works too ... never tested) that 'not equals' is !=

hope that helps,
jpbarto
 
Old 09-29-2003, 03:52 AM   #3
svf
LQ Newbie
 
Registered: Sep 2003
Location: India
Distribution: PCQ Linux 8.0
Posts: 2

Rep: Reputation: 0
Yet Another Solution

The 'onblur' stuff does not work on my Mozilla Firebird browser (I think Mozilla based browsers might not support 'onblur'). You might want to make your code browser independent. Follow the JS 1.3 standards, they are supported by both IE5, IE6 and Netscape/Mozilla.

I get JS error on IE as soon as the page loads. I think the problem is with the '<>'. Use '!=' instead.

You might want to use jpbarto's logic. i.e instead of checking every combination for an empty field, just check if any one of the fields are empty.

Let us know what happens.

svf
 
Old 09-29-2003, 09:22 AM   #4
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Hi jpbarto and svf. Thank you for your suggestion
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
javaScript machine error UFC Linux - Software 0 12-02-2005 11:20 AM
firefox javascript quicktime error Strannik Linux - Software 0 10-21-2005 07:35 PM
Javascript error "is null or not an object" apt Programming 2 03-28-2005 06:14 AM
JavaScript error when trying to play media player file degraffenried13 Linux - General 0 07-24-2004 08:29 AM
Javascript Error: Has no properties g00$e Programming 0 10-10-2003 11:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration