Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 06-20-2006, 05:26 AM Hide/Show Label
Average Talker

Posts: 25
Trades: 0
Hi, Back again

I was kindly given some code to enable me to hide/show a textarea dependant on a select list. .
I would like to also hide/show a label that goes with the text area and you'ld think I could work that out for myself, but no!

Can anyone steer me in the right direction with the code I've attempted?

Code:
<script type="text/javascript"> //<![CDATA[ function toggleSubmit(sel) { var submit = document.getElementById('submit'); var label = document.getElementById('justificationl'); var textarea = document.getElementById('justification'); submit.value = (sel.options[sel.selectedIndex].value=="yes") ? 'Submit Emergency Change' : 'Submit to Change Control'; textarea.style.display = (submit.value == 'Submit Emergency Change') ? 'block' : 'none'; } //]]> </script> </head> <body> <form id="form1" action="#" method="post"> <div> <label for="emergency">Emergency Change?: </label> <select id="emergency" name="emergency" onchange="toggleSubmit(this);"> <option label="Yes" value="yes">Yes</option> <option label="No" value="no" selected="selected">No</option> </select> <br /> <label for="justification1" name="justification1" style="display:none;">Please provide justification for emergency change </label> <textarea id="justification" name="justification" cols="38" rows="3" style="display:none;" title="Please provide justification for emergency change"></textarea> <input id="submit" name="submit" type="submit" value="Submit to Change Control" /> </div> </form> </body></html> <body>




I have highlighted the code that I added and hopefully some-one will be able to immediately spot where I've gone wrong.
Thanks in advance
devine is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-20-2006, 01:08 PM Re: Hide/Show Label
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
I just moved the label and the textarea into a <div> and had the script show/hide that DIV:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<script type="text/javascript">
		//<![CDATA[
			function toggleSubmit(sel) {
				var submit = document.getElementById('submit');
				var area = document.getElementById('jarea');
				submit.value = (sel.options[sel.selectedIndex].value=="yes") ? 'Submit Emergency Change' : 'Submit to Change Control';
				area.style.display = (submit.value == 'Submit Emergency Change') ? 'block' : 'none';
			}
		//]]>
	</script>
	</head>

	<body>
		<form id="form1" action="#" method="post">
			<div>
				<label for="emergency">Emergency Change?: </label> <select id="emergency" name="emergency" onchange="toggleSubmit(this);">
					<option label="Yes" value="yes">Yes</option>
					<option selected="selected" label="No" value="no">No</option>
				</select> <br>
				<div id="jarea" style="display:none;">
					<label for="justification">Please provide justification for emergency change </label><br><textarea title="Please provide justification for emergency change" name="justification" rows="3" cols="38"></textarea>
				</div>
					<input id="submit" type="submit" name="submit" value="Submit to Change Control">
			</div>
		</form>
	</body>

</html>

Last edited by funkdaddu; 06-20-2006 at 01:11 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 06-20-2006, 04:38 PM Re: Hide/Show Label
Average Talker

Posts: 25
Trades: 0
Hi funkdaddu,
Thanks so much - just what I was looking for!
devine is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Hide/Show Label
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62778 seconds with 12 queries