<Span> Visibility option

Trouble hiding a span

Page 1 of 1

1 Replies - 6416 Views - Last Post: 20 April 2010 - 08:12 AM

#1 TravisP  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 06-January 10

<Span> Visibility option

Posted 20 April 2010 - 04:07 AM

Hey all,

I'm working on my first web development assignment, but am a little stuck on how to hide the span text.

To give you an idea of what I have been trying so far:

Surname:	<input id="surname" type="text">
<span style="color: red"; id="surnameMissing"; visibility="hidden">
Surname is a required field.  
</span>


The problem is I still end up with "surname is a required field" next to my textbox.

The javascript I'm using seems to work okay as well.

function validate()
{
	if (document.Register.surname.value == "")
		{
			alert("Please fill in the 'surname' box.");
			document.Register.surname.focus();
			return false;
		}
	return true;
}



---

In case you didn't get that, I'm trying to make the red error text only appear next to a control if they aren't validated problem when the user submits the form.

Any ideas?

Cheers.

Is This A Good Question/Topic? 0
  • +

Replies To: <Span> Visibility option

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: <Span> Visibility option

Posted 20 April 2010 - 08:12 AM

visibility is a CSS attribute - try placing it like this:
<span id='surnameMissing' style='color:red;visibility:hidden'>


However, an item with visibility:hidden will still affect the layout of your document - so you may want to use display:none instead. Also, this would be much better accomplished by using a separate stylesheet; inline styles become very difficult to maintain once you have more than a handful of them on the page.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1