Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This works in IE but not in Netscape. Can anyone help me?

Status
Not open for further replies.

hautnueil

Programmer
Feb 21, 2002
25
0
0
US
I'm obviously a novice at Javascript. I would appreciate any help/push in the right direction.

Thanks in advance


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Javascript - Preview as you type</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<STYLE TYPE="text/css">
<!--
.MyClass {
font-family: Helvetica, sans-serif;
font-size: 12pt;
color: blue;
font-weight: bold
}
.MyClass_B {
font-family: Helvetica, sans-serif;
font-size: 12pt;
color: red;
font-weight: bold
}

-->
</STYLE>

<script language="JavaScript">
<!--
function changeCard(dest, src) {

if ((document.all)||(document.getElementByID)) {
var dSpan = eval('document.all.' + dest);
var sText = eval('document.frm1.' + src);

switch (src) {
case 'ThePersonName':
dSpan.innerHTML = sText.value + '<br>'
break;
}
}
}

//-->
</script>
</head>

<body bgcolor="#FFFFFF">

<form name="frm1" action="MyScript.name" method="post">

<table width="500" align="center" cellpadding="0" cellspacing="0" border="1">
<tr>
<th width="50%">Form Entry</th>
<th width="50%">On Screen View</th>
</tr>


<tr>
<td>
<input type="text"
name="ThePersonName"
size="20"
onkeyup="changeCard('spPerson','ThePersonName');"
onchange="changeCard('spPerson','ThePersonName');"
style="font-family:monospace"
value=""
maxlength="50">
</td>

<td class="MyClass">
<span id="spPerson"></span>

</td>

</tr>

<tr>
<td><input type="submit" name="submit" value="Submit"></td>
<td class="MyClass_B">Text entered in Form Field should appear in BLUE in box above this one</td>
</tr>

</table>
</form>
</body>
</html>
 
I forgot to mention that I need to incorporate this into a working site by tomorrow :-(
 
There is no need for eval() stuff... and mozillas don't recognize document.all. So:
Code:
<script language="JavaScript">
    <!--
function changeCard(dest, src) {
	var dSpan = document.getElementById( dest );
	var sText = document.forms["frm1"][src];
            
	switch (src) {                
   	case 'ThePersonName':                
      	dSpan.innerHTML = sText.value + '<br>'                        
         break;
	}
}
    //-->
    </script>
 
Your suggestions still work in IE but not in Netscape.
The Javascript debugger says that:
document.getElementById is not a function.
 
Are we talking about ol' Netscape Communicator 4 perhaps?
 
Argh... sorry, my NC4 code library is simple:
Code:
if( document.layers )
   alert("Are you kidding?!");
It supports neither innerHTML or getElementById. Both can be faked/simulated with layers and write() function but with some limitations and possible side-effects.
 
LOL!!!!

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
well my logs tell me that only a small percentage of my users are still using older versions of Netscape.
I'll just have to convince them to upgrade.

Thank you for all your help. You're a life saver.
 
hautnueil-

What is the possibility of convincing your users to wake up and use NS-anything-above-4?

A simple upgrade will save you hours of headache.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top