DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Discuss "display problem checkbox" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old May 30th, 2008, 10:47 AM
Contributing Member

 
Join Date: Mar 2008
Posts: 185
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default display problem checkbox

Hi,

I have a group of checkboxes

when the user clicks on the Other checkbox i want to show a textbox

Here is my code but it doesnt work the page is refreshed when the checkbox is clicked i see the textbox and it disappears

Code:
<%
displayopt = "none"
%>

function showtextbox()
{
if(document.frm1.c2j.checked == true) 
{
alert("checkedc");
hideAll2();
changeDiv('display', 'block');
}
else
{
alert("unchecked");
hideAll2();
}
}

function changeDiv(the_div,the_change)
 {
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }
function hideAll2()
 {
	changeDiv("display", "none");
 }
function getStyleObject(objectId)
{ 
	if (document.getElementById && document.getElementById(objectId))
		{
			return document.getElementById(objectId).style;
		}
	else if (document.all && document.all(objectId))
		{
		return document.all(objectId).style;
		}
	else
		{
		return false;
		}
}


<input type="checkbox" name="c2a" id="c2a" name="Reserves"> Reserves
<input type="checkbox" name="c2b" id="c2b" name="Army"> Army
<input type="checkbox" name="c2c" id="c2c" name="Navy"> Navy
<input type="checkbox" name="c2d" id="c2d" name="Air Force"> Air Force
<input type="checkbox" name="c2e" id="c2e" name="Trainee"> Trainee
<input type="checkbox" name="c2f" id="c2f" name="Cops"> Cops

<input type="checkbox" name="c2g" id="c2g" value="Other" 
<% if Request.form("c2g")= "Other" then 
Response.Write "checked=""true""" 
Else
Response.Write "" 
end if
%>
onClick="this.form.action = '<%=Request.ServerVariables("Script_Name")%>'; this.form.submit();  showtextbox();">Other 

<div id="display" style="display: <%=displayopt%>;">
<input type="textbox" name="othertext" id="othertext" size="35" value=""/>
</div>
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old May 30th, 2008, 01:04 PM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 537
Thanks: 14
Thanked 40 Times in 39 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

I wouldn't even bother submitting the form when you click it. Just call a JavaScript function to change the visibility on the onclick event.
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
  #3 (permalink)  
Old May 30th, 2008, 01:57 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 26 Times in 26 Posts
Blog Entries: 1
Rep Power: 1
richyrich is on a distinguished road

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I agree with JMH. Seems a very roundabout way to get something so simple done.
Try this:-
Code:
 
<input type="checkbox" name="c2a" id="c2a" name="Reserves"> Reserves
<input type="checkbox" name="c2b" id="c2b" name="Army"> Army
<input type="checkbox" name="c2c" id="c2c" name="Navy"> Navy
<input type="checkbox" name="c2d" id="c2d" name="Air Force"> Air Force
<input type="checkbox" name="c2e" id="c2e" name="Trainee"> Trainee
<input type="checkbox" name="c2f" id="c2f" name="Cops"> Cops
 
<input type="checkbox" name="c2g" id="c2g" value="Other" onClick="if(this.checked){document.getElementById('othertext').style.visibility='visible'}else{document.getElementById('othertext').style.visibility='hidden'}">Other 
 
 
<input type="textbox" name="othertext" style="visibility:hidden;" id="othertext" size="35" value=""/>
Hope that helps.
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
mehere (May 30th, 2008)
  #4 (permalink)  
Old May 30th, 2008, 03:26 PM
Contributing Member

 
Join Date: Mar 2008
Posts: 185
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

richyrich,

the reason why i have a page submit is because depending on what value they selected for the checkbox
i display a different section of questions

thats why so if its other i display a total different section of questions and also get the value of other

so i need the page to be submitted and a textbox to be displayed when the other checkbox is clicked

todd
Reply With Quote
  #5 (permalink)  
Old May 30th, 2008, 03:58 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 26 Times in 26 Posts
Blog Entries: 1
Rep Power: 1
richyrich is on a distinguished road

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

If you're going to submit the page, why bother using Javascript to display the textbox?

Just have:-
Code:
if request.form("c2g") = "Other" then
response.write("<input type=""textbox"" name=""othertext"" id=""othertext"" size=""35"" value="""" />")
end if

Comments on this post
jmurrayhead agrees: indeed, JavaScript wouldn't be needed in this case.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display textboxes problem todd2006 JavaScript Programming 13 May 22nd, 2008 02:54 PM
display problem todd2006 JavaScript Programming 19 May 12th, 2008 02:08 PM
text display problem todd2006 HTML & CSS Help 10 May 7th, 2008 08:14 PM
display problem with drop downs todd2006 JavaScript Programming 3 May 5th, 2008 05:31 PM
IE and Mozilla display problem todd2006 HTML & CSS Help 11 April 18th, 2008 01:17 PM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 08:34 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

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 44 45 46