homepage Welcome to WebmasterWorld Guest from 54.196.62.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript/CSS Not Working in NN
sartn




msg:1485871
 10:28 am on Apr 1, 2003 (gmt 0)

Hi,
Can any one provide a solution to make to below code working in Netscape also.It works fine in IE but in Netscape it gives java script error StylAsset not found.

<html>
<head>
<script type="text/javascript">
function validate()
{
x=document.myForm
at=x.myEmail.value.indexOf("@")
if (at == -1)
{
StylAsset.style.display = "block";
return false
}
}
</script>
</head>

<body>

<form name="myForm"
action="tryjs_submitpage.htm"
onsubmit="return validate()">
Enter your E-mail address:
<input type="text" name="myEmail">
<input type="submit" value="Send input">

<SPAN ID=StylAsset Style="display:none;">
<font size=2 color=red> Please enter text!
</SPAN>

</form>
</body>
</html>

Thanks in advance ,
sarrtn

 

Nick_W




msg:1485872
 10:38 am on Apr 1, 2003 (gmt 0)

Looks like some kind of JS issue?

Perhaps you could explain what the problem is?

Thanks

Nick

sartn




msg:1485873
 10:54 am on Apr 1, 2003 (gmt 0)


StylAsset.style.display = "block";
this line sets the span visible if validation fails.

StylAsset is the SPAN ID in HTML.
In netscape gives error that StylAsset not accessible.

But in IE it works.

I think the problem is placing the script in right place.

Could you help me how to achieve this.

Thanks in advance ,
Abdul Raheem .S

tedster




msg:1485874
 11:36 am on Apr 1, 2003 (gmt 0)

Change this line:

StylAsset.style.display = "block";

to this:

document.getElementById('StylAsset').style.display = "block";

Works in all modern browsers, AFAIK.

(PS - the font tag should be closed)

sartn




msg:1485875
 12:01 pm on Apr 1, 2003 (gmt 0)

Thanks for your valuable reply.

But it gives error message,
JavaScript Error:
file:/C¦/WINNT/Profiles/raheems/Desktop/New HTML
Document.htm, line 15:

document.getElementById is not a function.

Could you please help me?

WibbleWobble




msg:1485876
 12:37 pm on Apr 1, 2003 (gmt 0)

Which netscape? Doesn't NS4 use document.layer instead of elementbyID?

If that is the case, and I've remembered correctly, then a simple function to check whether the browser has a object called document.layer(s?) or getelementbyID ought to work, right?

Javascript isn't my fortaaaay.

tedster




msg:1485877
 8:37 pm on Apr 1, 2003 (gmt 0)

If you need NN4 support you'll need to rethink the approach. In NN4, if the display attribute is initially set to "none", then it cannot be addressed dynamically. You're just stuck with an element that is not rendered on screen.

You can try working with the visibility property and adding in some object testing to make sure each browser version gets the code it needs. Or perhaps just have your validate() function trigger an alert box when its tests fail. But you can't dynamically change the display attribute in Netscape 4. It's a well documented bug.

ricfink




msg:1485878
 4:23 am on Apr 3, 2003 (gmt 0)

I think the span element can't be set to display block.
It absolutely, positively must be an inline element.
It just won't accept the block style property.

(Unlike div which can be set to inline.)
how about a div that gets set to display: inline, instead?

This might be the source of the problem, I've run into it before.

tedster




msg:1485879
 5:36 am on Apr 3, 2003 (gmt 0)

I think you're right - <div> and <span> were conceived of as a pair, where <div> is block and <span> is inline. I've never tried it but I'll bet you can't make a div display inline either!

W3C Reference [w3.org]

ricfink




msg:1485880
 3:13 pm on Apr 3, 2003 (gmt 0)

No, actually you can make a div inline. You just can't make a span block.

I looked up the HTML spec last night after I posted and it seemed to support what I said. (Reading specs can be frustrating.)

The div was conceived as a container element for both inline and block elements but the span can only contain other inline elements.

joshie76




msg:1485881
 3:52 pm on Apr 3, 2003 (gmt 0)

I can't see any reason why you shouldn't be able to change div -> inline and/or span -> block (I also can't think of any reasons why you would want to :-))I've just tried the following code:


<span id="plop" style="display:block;border: 1px solid green">span - block</span>
<div id="poo" style="display:inline;border: 1px solid green">div - inline</div>
<span id="plop" style="display:inline;border: 1px solid green">span - inline</span>
<div id="poo" style="display:block;border: 1px solid green">div - block</div>

...and it works a treat in IE and NN6, which browser wasn't allowing you to do this?

(PS - I also tested changing the display property using script and this worked ok too)

ricfink




msg:1485882
 8:37 pm on Apr 3, 2003 (gmt 0)

The following definitely works but if NN4 is the issue, I don't know what to tell you to do except ignore NN4!

function validate() {
var x = document.myForm
var at = x.myEmail.value.indexOf("@")
if (at == -1) {
document.getElementById('StylAsset').style.display = 'block';
return false;
}
}
Or, how about a pop-up alert instead of the red text thing?
Much better if you ask me. Works fine in NN4.7.

function validate() {
var x = document.myForm
var at = x.myEmail.value.indexOf("@")
if (at == -1) {
alert('Invalid format of email address.\n Please re-enter it.')
return false;
}
}

tedster




msg:1485883
 9:32 pm on Apr 3, 2003 (gmt 0)

The div was conceived as a container element for both inline and block elements

Right - and an inline element cannot contain a block element, so changing a <div> to inline could make trouble.

A related example - lots of common errors result when people forget that <p> is a block element and then try to put paragraph tags inside an inline element, like <strong>

sartn




msg:1485884
 11:42 am on Apr 9, 2003 (gmt 0)

Hi,
Thanks for all your valuable suggestions.
But here problem is not with span or div.
It's getting the span or div tag id in the JS to change the value dynamically in NN4.7 .

So, If any of have good idea other than alert message to display error message welcome.

Thanks in advance,
Abdul Raheem .S

joshie76




msg:1485885
 11:52 am on Apr 9, 2003 (gmt 0)

Hi Sartn,

Sorry, we often get sidetracked! I'm confident to say there is NO WAY to change the contents of a span tag in NN4.7, it's a real dinosaur when it comes to DOM manipulation.

ASP.NET considers NN4.7 a 'down-level' browser for this very reason and has to go off to server to change the page.

You may be able to do something with layers (I stopped playing with Script in NN4 a looooooooong time ago) but I think your best bet (if you don't want to use an alert) is a postback to server to rebuild the page with your "Enter Value" message.

Best of luck,

J

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved