Forum Moderators: open
<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
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
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.
(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.
W3C Reference [w3.org]
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.
<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)
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;
}
}
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>
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