473,735 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hide form field

Hi,

I had a javscript what does the follow. When a checkbox is yes then i will
see a form field. When a checkbox is no i dont see the form field.

Can somehelp me for that script ?

Greets Wouter
Jul 23 '05 #1
5 6780
Wouter wrote:
I had a javscript what does the follow. When a checkbox is yes then i will
see a form field. When a checkbox is no i dont see the form field.
<form>
<input type="checkbox"
checked="checke d"
onclick="
this.form.eleme nts['bar'].style.visibili ty=
this.checked?'v isible':'hidden ';"

<input type="text" name="bar">
</form>

Though this doesn't prevent you from server-side checking;-)
Jul 23 '05 #2
Yann-Erwan Perio wrote:
Wouter wrote:
I had a javscript what does the follow. When a checkbox is yes then i
will see a form field. When a checkbox is no i dont see the form field.

<form>
<input type="checkbox"
checked="checke d"
onclick="
this.form.eleme nts['bar'].style.visibili ty=
this.checked?'v isible':'hidden ';"
>

<input type="text" name="bar">
</form>

Though this doesn't prevent you from server-side checking;-)

I'd also add the following onload:

<body onload="
var a=document.getE lementsByTagNam e('form');
for (var i=0;i<a.length; ++i){a[i].reset();}"
Some browsers don't reset forms when you re-load the page, so you may end up with a field displayed that is un-checked. The script above resets all the forms in the page when it's loaded. You may also want to add something that clicks all the "checked" input elements to make sure their onclick event has fired too.

Last thing: you can also hide stuff using "display: none". The difference is that if something is invisible, it still takes up room on the page. If it's not displayed, it doesn't. See what happens below to the 'X'.

<head><title>vi sible &amp; display</title></head>

<body onload="
var a=document.getE lementsByTagNam e('form');
for (var i=0;i<a.length; ++i){a[i].reset();
">
<form>
<table>
<tr>
<td>visibilit y method:</td>
<td>
<input type="checkbox"
checked="checke d"
onclick="
this.form.eleme nts['bar'].style.visibili ty=
this.checked?'v isible':'hidden ';" </td>
<td><input type="text" name="bar">X</td>
</tr><tr>
<td>display method:</td>
<td>
<input type="checkbox"
checked="checke d"
onclick="
this.form.eleme nts['foobar'].style.display=
this.checked?'' :'none';"

</td>
<td><input type="text" name="foobar">X </td>
</tr>
</table>
</form>
</body>
</html>

PS. I hope the wrapping/blocking turns out OK, I'm still getting used to this news client...
Jul 23 '05 #3
RobG wrote:

<body onload="
var a=document.getE lementsByTagNam e('form');
for (var i=0;i<a.length; ++i){a[i].reset();


Arggghhh! The closing "}" is missing from the onload in the lower code block.... use the onload from the top and all will be sweet (or just delete the leading "{").

Sorry.
Jul 23 '05 #4
RobG wrote:
Last thing: you can also hide stuff using "display: none". The
difference is that if something is invisible, it still takes up room on
the page. If it's not displayed, it doesn't. See what happens below to
the 'X'.
Good point, this might indeed be preferable in some situations.
PS. I hope the wrapping/blocking turns out OK, I'm still getting used
to this news client...


It seems fine here, however the line length wasn't wrapped when I
checked Google's archives, so it could display the same in other
newsreaders (maybe due to your charset encoding?).

<URL:http://groups.google.c om/groups?selm=MwN 1d.1111%24aA.40 558%40news.optu s.net.au>

Since you seem interested on this topic, I'd like to suggest the
following resource, which goes into details into c.l.j posting standards:

<URL:http://www.jibbering.c om/faq/faq_notes/pots1.html>

You can also use alt.test to post test messages, playing with signatures
etc. Welcome on Usenet!
Regards,
Yep.
Jul 23 '05 #5
Tanks that is wgere i`m looking for!

Greets Wouter

"RobG" <rg***@iinet.ne t.auau> schreef in bericht
news:oD******** *********@news. optus.net.au...
RobG wrote:

<body onload="
var a=document.getE lementsByTagNam e('form');
for (var i=0;i<a.length; ++i){a[i].reset();


Arggghhh! The closing "}" is missing from the onload in the lower code
block.... use the onload from the top and all will be sweet (or just
delete the leading "{").

Sorry.

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
148643
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected value="">Please make a selection</option> <option value="1">Choice 1</option> <option value="2">Choice 2</option> <option value="3">Choice 3</option>
2
30034
by: Xerxes | last post by:
Hi, can you tell me how I can make a <label> hidden? I have hidden the field after the label: var M_Hide = isNS4?'hide':'hidden'; var M_Show = isNS4?'show':'visible'; ..... <label id="uid">UserID: </label> <input name="UserID" type="text" value="" size="20"> <script language="Javascript1.2" type="text/javascript1.2">
9
2768
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your response. Sergio ------------------------------------------------ <script language="JavaScript" type="text/javascript">
10
13459
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group related to checkboxes. Thanks!!!
2
14878
by: K B | last post by:
Hi, Is there ANY WAY to hide a row/field in a DetailsView based on meeting a condition at the ItemCreated or ModeChanging event -- or any other way? There appears not to be, but I was hoping for confirmation before totally giving up. Thanks, Kit
7
29153
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field below the comment with a spell check & submit button. Clicking "Amend" would display the same buttons & text field but pre-populated with the original comment. Using Java Script how do I show / hide the text field in my list of comments but have...
3
2796
by: toodi4 | last post by:
I'm using a javascript that hides and unhides text based on a button click. It works great across static fields on a form. The problem I have is that I'm trying to hide and unhide various fields that are populated on the page by a database. In other words, sometimes there are 4 fields, sometimes 6. I've used various scripts for the hide/unhide function. This is one I'm using now that I've copied from another source: <script...
10
11760
by: sara | last post by:
Hi - Is it possible to hide the detail section of a report at run time? I have a report that prints all details, with summary lines. The user would like the report ALSO with just summary lines. It seems the simplest thing is to run the code (see below) once with the detail section showing, and a second time hiding the detail section. I can't figure out the code to do that and don't see it posted.
0
8991
Frinavale
by: Frinavale | last post by:
This code snippet is just a little bit of fun. It demonstrates how you use JavaScript and CSS to show or hide columns in a table depending on whether or not a checkbox corresponding with the column is checked. <html> <head> <script type="text/javascript"> function ShowHideField(header, gridID, checkboxElement) { var theGrid = document.getElementById(gridID); var displayValue;
0
8786
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9466
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6748
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6050
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4567
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3278
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.