Show and Hide Text - how do I do that?

This is a discussion on "Show and Hide Text - how do I do that?" within the JavaScript Forum section. This forum, and the thread "Show and Hide Text - how do I do that? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 28th, 2007, 17:23
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Question Show and Hide Text - how do I do that?

Is there a simple way, through the use of the onclick event, to show and hide text? I don't want to use a <div> unless completely necessary.
Basically I have a form, and it contains username and password text fields, depending on which <radio> button is hit, the username/password fields will be disabled (already coded that part) and I also want the red * next to these fields to disappear, so the user further realizes that the username/password fields don't need to be filled in.

Is there a quick way to do this with the onclick() event in javascript?

I know, I know...I really need to learn javascript already
Reply With Quote

  #2 (permalink)  
Old Mar 29th, 2007, 00:23
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,619
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Show and Hide Text - how do I do that?

You don;t necesserally need a div, but you'll need a paragraph/fieldset/span or something to wrapt the elements you want to show/hide.

Anyway, I'll point you in the right direction: jQuery.
I have not tested the following, I just typed it as I went along...
But that's the basic idea:

HTML: Select all
<form action="login.asp">
<input type='radio' name='mode' id='by-username' /> By Username - 
<input type='radio' name='mode' id='by-password' /> By Password
<br/>
 
Username/password: 
<input type='text' id='username' name='username' value='username' />
<input type='text' id='email' name='email' value='password' style='display:none;' />
<br/>
 
Password: <input type='text' id='password' name='password' />
</form>
Code: Select all
<script>
$(function(){
$('#by-username').click(function(){
$('#username).show();
$('#email).hide();
}
$('#by-email').click(function(){
$('#username).hide();
$('#email).show();
}
})
</script>
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)

Last edited by karinne; Mar 30th, 2007 at 15:08. Reason: Please use [code]...[/code] tags when displaying code!
Reply With Quote
Reply

Tags
hide text, show text

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show/Hide text fields based on drop down sing2trees JavaScript Forum 1 Apr 22nd, 2008 21:01
CSS Show Hide with JS abis123 JavaScript Forum 4 Dec 13th, 2007 05:39
[SOLVED] Show&amp;Hide Div Box Maska JavaScript Forum 6 Oct 1st, 2007 11:04
Show/Hide JS pa007 JavaScript Forum 0 Apr 6th, 2007 19:18
Show/Hide Div Help Trebz JavaScript Forum 2 Feb 21st, 2006 22:37


All times are GMT. The time now is 22:31.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43