Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Javascript with netscape


Message #1 by yuqiant@h... on Mon, 26 Feb 2001 16:00:01
Your problem is not helped by FrontPage producing some dodgy HTML - try 
using something like HTML tidy from the W3 site which validates and tidies 
up HTML.  Anyway back to your problem - Netscape is very touchy about 
using the document object to refer to forms etc.  So try using 
value=document.form1.text1.value and so on.  In general the way to do 
validation is to use the onBlur or onChange events.  Here's an example 
which works in NS and IE:
<html>
<head>
<title>Focus validation</title>
<script language="Javascript" type="text/javascript">
<!--
function window_onLoad()
{
    document.form1.text1.focus();
}

function check1 (textObj)
{
        var value;        
        value = textObj.value;
        if (value != "First" )
        {
           alert("Something wrong, try again!");         
           textObj.focus();
           textObj.select();
           return false;        
       }
       return true;
 }
//  -->
</script>
</head>
<body bgcolor="#eeeeee" onLoad="window_onLoad();">
<form name="form1" id="form1" onsubmit="return check1
(document.form1.text1);">
    <p>Please enter "First" in first textbox</p>        
    <input id="text1" name="text1" onBlur="check1(this);"><br>
    <input name="text2" id="text2" >
</form>
</body>
</html>

  Return to Index