[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

Show/Hide Text Box Based on Check Box

I would like to know how to show/hide a text box or a group of text boxes based on a checkbox value i.e. checked or not.

The page should not need to refresh and should be able to display the form elements immediately if the checkbox is checked or not.

i do not want to use javascript as this would limit the code to working with java enabled browsers.

I would prefer HTML or asp or combination of the both.

Should work and have been tested in I.e. 5 and ns4 or 5 .

I appreciate your help.

Thanks.
Ricky
0
Ricky11
Asked:
Ricky11
  • 5
  • 2
  • 2
  • +1
1 Solution
 
aprestoCommented:
try this:

<form>
<input type="checkbox" name="cb1" value="0" onclick="javascript:check(0);">
<input id=txtTextField1 type=text name=txtTextField1 style="display:'';">

<script language="javascript">
function check(id)
{if (id==0) {document.all('txtTextField1').style.display='none'} else

{document.all('txtTextField1').style.display=''}}
</script>

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21253613.html?query=hide+text+box+checkbox&clearTAFilter=true
0
 
Ricky11Author Commented:
anyway to do it without javascript at all as my question suggested?
0
 
peh803Commented:
@apresto -- long time no see!  
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aprestoCommented:
@Ricky

sorry i think i speed read and missed that, there isnt any way to di it if you want it to take effect at client side, otherwise you will need to submit the page every time a check box is checked

@Peh

Sup Dude! I know, I havent been around lately, i finally got a development job out of college and havent had much time, but i pop in for a visit occasionally! See you;re still sharing your words of wisdom :o)
0
 
peh803Commented:
@Ricky11 :

ASP by its very nature requires a page refresh for it to be compiled.  ASP is a server-based language, and thus it is not possible (it my knowledge anyways!) to build a page in classic ASP that does much of anything on the server.  Typically, ASP developers will mix ASP (server side code) with javascript (client side code) to handle most things.  

Even .NET, the newest technology from M$, uses javascript.  It just writes it for you at run time...

So, the point is, I fully understand your reservation with the fact that when you use js, that means that the client browser will have to have javascript enabled, but this is fairly standard these days, so I wouldn't worry about it.  

You could potentially use client-side vbscript, but this is not as widely supported as javascript, so I wouldn't recommend it.  

Sorry the news wasn't better!  

You'll have to either deal with a page refresh (i.e., use ASP), or deal with javascript.  

Sorry, in this case, I don't think you can "have your cake and eat it, too."  :-)

Regards,
Phil
0
 
peh803Commented:
@apresto -- congrats on the new job.  That's exciting.  I haven't been on as much lately as I'd like, but when I get a chance, I still pop in for a comment or two, here and there :)
0
 
Neil ThompsonSenior Systems DeveloperCommented:
hi, can you use Microsoft.XMLHTTP ? does this not post back to the server without a refresh and update?

this example is .net but you'll have a jumping off point : http://support.microsoft.com/kb/893659

Neil
0
 
peh803Commented:
I have used XMLHTTP in classic ASP for doing client side postbacks to the server and receiving a response...

But you still need to use a server-side language to do the posting / receiving of data...

I don't know the details of the article you've posted above, but I would bet that the .NET code compiles into a web app that also uses javascript to handle the client-side interractions.

When I did it using classic ASP, I used javascript.  And doesn't that seem like overkill to go through all this just to toggle a textbox's display property?  

Regards,
Phil
0
 
Ricky11Author Commented:
peh803

Thanks for the insight.

Okay I have tried to implment your script.

It works only half way. I.e. when the page loads the text box is displayed already and then when i click on the text box "checked" it disapear. (suppose to appear when it is checked"

and then when i unchek it it doesn't appear again, and the script dies.

tks anyway.
0
 
peh803Commented:
@Ricky :

I'm happy to provide any insight you like!  But if the script isn't working, let's work on it and fix it!

If I understand, you're trying to show / hide a text box when a checkbox is clicked or not?  Is that right?

What state would you like the page to be in once you load the page for the first time?  I'm sure I can work with you to get this working properly.  Since that was actually part of this question that hasn't been answered, you don't need to open a new question.  We can just work on it here.

Let's get it working!

Regards,
Phil
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now