• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript in Netscape4.7

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing some problem with Netscape4.7.The javascript code that works fine in IE?(internet explorer) doesn't work in Netscape.What are the requisite changes to be made in the code so that javascript validation works fine in Netscape4.7.
It gives Javascript error.

The code is as follows
<html>
<head>
<SCRIPT language=JavaScript><!--/******************************************The next section automatically adds '(', ')',and '-' characters to phone number fieldsas the user types (so the user only needsto type the 10 numbers).******************************************/");
function phoneDisplay(i, delKey)
{ if(delKey!=8 && delKey!=46 && delKey!=9 && delKey!=16 && !(delKey>36 && delKey<41))
{
//if the delete, backspace, tab, shift, are not the keys that caused the keyup event.");
var fieldLen = i.value.length;var areaCode = ""; var exchange ="";
var lastFour = "";var currVal = i.value;var firstParens = 1;
var firstParens = parseInt(i.value.lastIndexOf("(")) + parseInt(1);
var secondParens = 5;var secondParens = parseInt(i.value.lastIndexOf(")")) + parseInt(1);
if(firstParens < 1){ firstParens=1; }
if(secondParens < 1){ secondParens=5; }
if(fieldLen==1 && currVal!="(")
{ areaCode = i.value; }
if(fieldLen>1)
{areaCode = i.value.substring(firstParens,4);}
if(fieldLen>4){exchange = i.value.substring(secondParens,8);}
if(fieldLen>7){lastFour = i.value.substring(9,13);}
//alert("x" + lastFour + "y");");
if(fieldLen<4){i.value = "(" + areaCode ; i.focus();}
elseif(fieldLen<8)
{i.value = "(" + areaCode + ")" + exchange;i.focus();}
elseif(fieldLen<13){i.value = "(" + areaCode + ")" + exchange + "-" + lastFour; i.focus(); } } }
//end if delete key=8,46}");
function phoneBlur(i){
var formName= document.forms[0].name;
if(i.value.length<5)
{i.value="";}}
function phoneFocus(i)
{ var formName = document.forms[0].name;
var formLength =document.forms[0].length;
if((i.value==""))
{i.value="("; i.focus(); i.select(); }
else { i.select(); }}
function testKey(e){
chars="0123456789";
e=window.event;
if(chars.indexOf(String.fromCharCode(e.keyCode))==-1)
window.event.keyCode=0;
}
//-->
</SCRIPT>
<SCRIPT event=onfocus for=telephonenumber1>phoneFocus(this);</SCRIPT>
<SCRIPT event=onfocus for=telephonenumber2>phoneFocus(this);</SCRIPT>
<SCRIPT event=onfocus for=faxnumber>phoneFocus(this);</SCRIPT>
<SCRIPT event=onblur for=telephonenumber1>phoneBlur(this);</SCRIPT>
<SCRIPT event=onblur for=telephonenumber2>phoneBlur(this);</SCRIPT>
<SCRIPT event=onblur for=faxnumber> phoneBlur(this);</SCRIPT>

<SCRIPT event=onkeyup for=telephonenumber1>phoneDisplay(this, window.event.keyCode);</SCRIPT>
<SCRIPT event=onkeyup for=telephonenumber2>phoneDisplay(this, window.event.keyCode);</SCRIPT>
<SCRIPT event=onkeyup for=faxnumber>phoneDisplay(this, window.event.keyCode);</SCRIPT>
</head>
<body>
<form name="NC3" method="get" action="../../CD532_CustomerLocationWizard" onSubmit="return testdata(this)">
<table align=center class="CyDwWizDefaultColour">

<tr>
<td>Telephone Number 1<font color=\"#FF0000\">*</font></td>
<td>
<input type="text" name="telephonenumber1" DATASRC="#osia" DATAFLD="telephonenumber1" maxlength="13" onkeypress="testKey(event)">
</td>
</tr>
</table>
</form>
</body>
</html>

 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For netscape, in order to capture events you have to trap them differently than you do in IE. So with IE you can just say document.onkeypress to get your event, for Netscape you have to write it differently.
So for Netscape it looks like this:
document.captureEvents(Event.KEYPRESS) and that captures your keypresses. And then you direct it to the onKeyPress event with:
document.onkeypress
I am not sure if keypress is an event in Netscape so you may have to double check that and change it to onkeyup or something like that.
Check out this link for more info on how to capture events in Netscape and IE:
http://www.webreference.com/dhtml/column3/capEvents.html
Hope that gives you a start.
Bill
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to make code compatible for both ie & netscape, but netscape 4.7 has many difficulties.a few are listed
Block hiding / Display:none, property not working, visible not working(Visibility='Hidden' or Visibility='visible' not working for TR , TD, DIV, TABLE.
inserting a frame through insertAdjacentHTML document.body.insertAdjacentHTML("beforeEnd","<IFRAME name='IOFrame' width=0 height=0></IFRAME>");
this works in ie and nn6.0 but not in 4.7!!
to create and submit hidden forms does not work tried using layers but still does not work. Can we not have dynamic pages in netscape?
Will someone pls share a idea on how to do it.
Thanks in advance
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic