473,756 Members | 3,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enable/disable radio buttons

pradeepjain
563 Contributor
Expand|Select|Wrap|Line Numbers
  1. for($i = 1; $i <= 15 ; $i++){
  2. for($k = 1; $k <= 10 ; $k++){
  3. $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
  4. }
  5. }
  6. $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
  7. <script type='text/javascript'>
  8. function test(name){
  9.         document.ratings.rating1.disabled = false;
  10.         document.ratings.rating2.disabled = false;
  11.         document.ratings.rating3.disabled = false;
  12. alert('hai');
  13. }
hi i am working on a product site where in i display 10 radio button for 15 features of a product for user to rate . and each check box is disabled by default and i add a rate it button "rate-it" which on click should enable 1 row of checkboxes . i tried to write code for tht . its print the alert msg and all. but enabling the checkboxes is not working any help on it!?
Dec 14 '09 #1
19 6591
RamananKalirajan
608 Contributor
Hi,
This is a sample code....

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. <script type="text/javascript">
  10. function enableRadio(rdId)
  11. {
  12.     //alert(rdId);
  13.     document.getElementById(rdId).disabled=false;
  14. }
  15. </script>
  16. </HEAD>
  17.  
  18. <BODY>
  19. <input type="radio" name="demoRadio" id="demoRadio" disabled="disabled"/>
  20. <input type="button" value="Enable It" onclick="enableRadio('demoRadio')">
  21. </BODY>
  22. </HTML>
  23.  
Thanks and Regards
Ramanan Kalirajan
Dec 14 '09 #2
Dormilich
8,658 Recognized Expert Moderator Expert
though this demo should work, it is not a solution to the question.

there are some questions, that should be answered beforehand.

mainly, your code does not match your description in any way:
- are you using checkboxes (as in the description) or radio buttons (as in the code)?
- do you want to rate it with a button (as in the description) or via link (as in the code)?
- your test function’s parameter is used nowhere
- should the radios be grouped (aka same name)?

Standardista’s corner:
Expand|Select|Wrap|Line Numbers
  1. <input type="radio" name="demoRadio" id="demoRadio" disabled="disabled"/>
should be
Expand|Select|Wrap|Line Numbers
  1. <INPUT type="radio" name="demoRadio" id="demoRadio" disabled>
in HTML 4.01 (although it is not treated as error)

as a general rule of thumb, write your code consequently in one style, e.g. all tag names upper case and all attribute names lowercase. makes up for a better reading experience (especially for those people, who shall have a look at your code later)
Dec 14 '09 #3
pradeepjain
563 Contributor
1)- are you using checkboxes (as in the description) or radio buttons (as in the code)?
2)- do you want to rate it with a button (as in the description) or via link (as in the code)?
3)- your test function’s parameter is used nowhere
4)- should the radios be grouped (aka same name)?
1) sorry for that error its radio buttons that i am using.
2) once he clicks on link/button the disabled property must get enabled . well it is a link as in the code.
3)sorry i had hardcoded the values in the test function to check the function
4) yeah a set of 10 radio buttons in a same row with same name .
Dec 14 '09 #4
pradeepjain
563 Contributor
here is an improved version of ma code

Expand|Select|Wrap|Line Numbers
  1.  for($i = 1; $i <= 15 ; $i++){
  2.  for($k = 1; $k <= 10 ; $k++){
  3.  $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
  4.  }
  5.  }
  6. $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
  7.  
  8. <script type='text/javascript'>
  9. function test(name){
  10.  
  11. //for (i=1; i<=10; i++){
  12. //  document.getElementById(name[i]).disabled=false; // tried this with the for loop..but error console gave an error like document.getElementById(name[i]) is NULL
  13.   document.getElementById(name).disabled=false;
  14. //}
  15.  
  16. alert(name);
  17. }
  18.     </script>
but still the enabling of the radio buttons is not working !
Dec 14 '09 #5
RamananKalirajan
608 Contributor
@pradeepjain

Expand|Select|Wrap|Line Numbers
  1. $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
In the above code "$i" is out of the loop. Where "i" is the loop index. Try to give this inside the loop or change the logic. As the "i" variable is holding juck data, it is not working for you.

@Dormilich
Attribute Minimization is not a good practice in XHTML 1.0. Is it ok to give like that. I will follow the code standards - all tag names upper case and all attribute names lowercase. Thanks for the information.

Thanks and Regards
Ramanan Kalirajan
Dec 15 '09 #6
pradeepjain
563 Contributor
Expand|Select|Wrap|Line Numbers
  1.  for($i = 1; $i <= 15 ; $i++){
  2.  for($k = 1; $k <= 10 ; $k++){
  3.  $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
  4.  }
  5. $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
  6.  }
  7.  
  8.  
  9. <script type='text/javascript'>
  10. function test(name){
  11.  
  12. //for (i=1; i<=10; i++){
  13. //  document.getElementById(name[i]).disabled=false; // tried this with the for loop..but error console gave an error like document.getElementById(name[i]) is NULL
  14.   document.getElementById(name).disabled=false;
  15. //}
  16.  
  17. alert(name);
  18. }
  19.     </script>

sorry for ma error..i wrote the code by hand over here so that cane out of the for loop. but then also its not working . in the javascript i have shown a for loop thing which i tried earlier but it gave the error which i have given over there .
Dec 15 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@pradeepjain

one of your core problems is, that you use multiple IDs, where they should be unique.

@RamananKaliraj an

I was not talking about XHTML (because hardly anyone really uses it). if you were to use XHTML and to use the XML parser (most people use the HTML parser), you’d be prompted with every mistake.
Dec 15 '09 #8
pradeepjain
563 Contributor
i will tell u the exact requirement .

each row will have 10 radio buttons in which only 1 can be clicked at 1 time . so like this there will be 7 rows like this . each row of radio buttons have a unique ID like rating1..rating 7 . so when i click on a rate-it link on each row tht row disabled property must get cancelled and the radio buttons must get enabled .

hope i made the concept clear and logic is correct also!!
Dec 15 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
each row of radio buttons have a unique ID like rating1..rating 7
this is where your code fails.
Dec 15 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2471
by: Manatee | last post by:
Hi group. I have exactly one external, alternate stylesheet that I want to enable or disable by form controls, on one page only (not saved across pages). I used: <link rel="alternate stylesheet" id="style-compact" etc...> <input name="view" type="radio" onclick="document.getElementById('style-compact').disabled=false">
1
4254
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES is selected - enable a field to use the M$ Datepicker. Using the code below works for most of our fields, however the problem is that when the field is re-enabled - it remembers the original date or data prior to it being disabled - despite the...
2
33850
by: teddy.am | last post by:
Guys, I have a set of 6 radio buttons, infront of each one there's a textbox .... i need all textboxes disabled .... once one of the radio buttons is selected, the texbox infront of it will be anabled to type in ... any fast solution?
2
26363
by: Kevin | last post by:
I've been looking all over and I can't seem to find what ought to be simple. I need to disable a drop down when a checkbox is checked, and enable it when same checkbox is unchecked. I've found any number of scripts to disable / enable a drop down but they are all made to work with 2 different buttons, radio group selections, etc. I can't seem to come up with one that can toggle off a single checkbox.
1
1928
by: scanreg | last post by:
My form needs to (1) direct to specified URLs based on a combination of form selections and (2) enable/disable form features based on selections within the form FORM Radio 1 - A - B - C Select Box 1
6
5552
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be enabled only if something is selected in the listview. That part specifically works but not very well. It seems that I can only get the buttons to disable if I click off the text of the items in the listview but still within about 10-20 pixels of...
3
11661
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm very new to VBA,i tried to follow the instructions reported in the code,but i got no result,i still can use the shift key,can you explain in details how to use it correctly to enable/disable users from pressing shift key to view database windw?,the...
3
2441
by: sumanbangladesh | last post by:
Hi I have a page with 3 radio butons. If I select a specific one,then I like to view some other radio buttons otherwise the other radio buttons will be remain disabled or invisible. I am very new in Javascript and waiting for your kind response Thanks in advance
0
9456
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
9273
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
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
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
9711
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...
0
8712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.