Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Sponsored Links

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
 
LinkBack Thread Tools Display Modes
  #1  
Old May 30th, 2008, 10:47 AM
Barn Frequenter
 
Join Date: Mar 2008
Posts: 197
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  
Old May 30th, 2008, 01:04 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 949
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server 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
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #3  
Old May 30th, 2008, 01:57 PM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
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  
Old May 30th, 2008, 03:26 PM
Barn Frequenter
 
Join Date: Mar 2008
Posts: 197
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  
Old May 30th, 2008, 03:58 PM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
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


All times are GMT -4. The time now is 03:50 PM.



Content Relevant URLs by vBSEO 3.2.0