473,749 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide buttons based on radio selection

I have a form with three radio options. And I have three buttons:
<input type="submit" name="mainform_ action" value="Edit Data">
<input type="submit" name="mainform_ action" value="View Data">
<input type="submit" name="mainform_ action" value="Delete Data">

If the first radio button is selected, I only want all three buttons to be
visible to the user.

If the second radio button is selected, I only want the "Edit Data" and "View
Data" buttons to be visible.

If the third radio button is selected, I only want the "View Data" button to be
visible.

Is it possible to accomplish this in Javascript? In particular, I want to
continue using the "input type=submit" buttons without having to create my own.
Jul 20 '05 #1
3 23887
Owen Funkhouser wrote:
I have a form with three radio options. And I have three buttons:
<input type="submit" name="mainform_ action" value="Edit Data">
<input type="submit" name="mainform_ action" value="View Data">
<input type="submit" name="mainform_ action" value="Delete Data">

If the first radio button is selected, I only want all three buttons to be
visible to the user.

If the second radio button is selected, I only want the "Edit Data" and "View
Data" buttons to be visible.

If the third radio button is selected, I only want the "View Data" button to be
visible.

Is it possible to accomplish this in Javascript?
Yes, it is. Enclose the radio *buttons* in a `fieldset' element or leave
them as children of the `form' element. Use the `onchange' event handler
of either element to call a user-defined method that sets the either the
`visibility' property to `hide' or `show' (Netscape 4.x), or the
`style.visibili ty' property to `hidden' or `visible' (others), depending
on the value of the `checked' property of the radio buttons. Good luck!
In particular, I want to continue using the "input type=submit"
buttons without having to create my own.


Null problemo.
PointedEars

Jul 20 '05 #2
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Enclose the radio *buttons* in a `fieldset' element or leave them as
children of the `form' element. Use the `onchange' event handler of
either element


I didn't know that forms or fieldsets had onchange event handlers.
Checking the HTML 4.01 specification gives no mention of these.

I tested in IE 6, Opera 7 and Mozilla, using the following code:
---
<form onchange="alert ('form')" action="">
<fieldset onchange="alert ('field')"><leg end>Test</legend>
<input name="too" onchange="alert ('input')">
</fieldset>
</form>
---
and it threw all alerts in in Opera and Moz. In IE, only the input alert
was displayed.

The code is valid HTML 4.01 strict except for the onchange attributes
in the form and fieldset tags.

It seems these non-standard event handlers are not implemented in IE,
so a solution using them might not be generally applicable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
~
Jul 20 '05 #3
On 23 Oct 2003 15:49:48 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > brought forth from the murky depths:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Enclose the radio *buttons* in a `fieldset' element or leave them as
children of the `form' element. Use the `onchange' event handler of
either element


I didn't know that forms or fieldsets had onchange event handlers.
Checking the HTML 4.01 specification gives no mention of these.

I tested in IE 6, Opera 7 and Mozilla, using the following code:
---
<form onchange="alert ('form')" action="">
<fieldset onchange="alert ('field')"><leg end>Test</legend>
<input name="too" onchange="alert ('input')">
</fieldset>
</form>
---
and it threw all alerts in in Opera and Moz. In IE, only the input alert
was displayed.


Along the same line, I need to check for empty fields and am currently
using this script to do so. The problem is that it doesn't check radio
button fieldsets (or checkboxes). How would I add that in the simplest
way? All she wants me to check for are empties.

<SCRIPT LANGUAGE="JavaS cript">
<!-- Original: wsabstract.com -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function checkrequired(w hich) {
var pass=true;
if (document.image s) {
for (i=0;i<which.le ngth;i++) {
var tempobj=which.e lements[i];
if (tempobj.name.s ubstring(0,1)== "x") {
if (((tempobj.type =="text"||tempo bj.type=="texta rea")&&
tempobj.value== '')||(tempobj.t ype.toString(). charAt(0)=="s"& &
tempobj.selecte dIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName= tempobj.name.su bstring(2,30).t oUpperCase();
alert("Please make sure the "+shortFieldNam e+" field is completed.");
return false;
}
else
return true;
}
// End -->
</script>

I add an x to the fieldname and strip off both the prefix letters
and the x. EG: name="xdname" is a required deliver-to name.

Is there a simple way to add radio button checking?

Jul 20 '05 #4

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

Similar topics

4
3608
by: Ken Fine | last post by:
I've made a content managment system that uses icons to represent page layouts. To choose a different layout, the user clicks on a radio button associated with each layout icon. On click of one of the radio buttons, the form submits and a new layout is chosen. I would prefer if people can click on the icons themselves , rather than using the radio buttons.The border or background associated with the selected icon can highlight...
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
12190
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow { display: none; }
5
3199
by: dje | last post by:
In the OnClick event on a radioButtonList, I run a javascript to show/hide the appropriate div along with a submit button, which displays as expected. The problem is the submit no longer works on the button. If I quit using the divs, and do a postback on the radiobutton selection, showing/hiding tables instead, the button is ok and continues to work. I've tried a variety of controls instead of the button in a variety of places but it...
3
1778
by: Mefistofeles | last post by:
Hello. Need help to make text-based radio buttons. On my calender site I want to have text that works like radio buttons. Exampel, bold text is the selected radio-text. Jan Feb Mar Apr May Jun Jul Aug ..... This is my code right now:
1
2570
by: stewdizzle | last post by:
I have a from with three radio buttons (same group) and three text boxes. The radio buttons give the user a choice of uploading one, two, or three images. Currently, I have the text boxes load as disabled and the radio button selection enables the needed text boxes. It works but... I don't want to see the text boxes unless they are needed and I want the user to be able to change their mind. (ie choose three images or go back to one image)...
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9568
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
9335
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,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6801
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
6079
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();...
1
3320
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
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.