473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

enable/disable radio buttons

pradeepjain
563 512MB
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 6565
RamananKalirajan
608 512MB
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 Expert Mod 8TB
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 512MB
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 512MB
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 512MB
@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 512MB
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 Expert Mod 8TB
@pradeepjain

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

@RamananKalirajan

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 512MB
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..rating7 . 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 Expert Mod 8TB
each row of radio buttons have a unique ID like rating1..rating7
this is where your code fails.
Dec 15 '09 #10
pradeepjain
563 512MB
you mean to say each radio button should have a diff id like rating11,rating12 for 1st row and rating21,rating22 for second row!!
Dec 15 '09 #11
Dormilich
8,658 Expert Mod 8TB
jepp, as demanded by the DTD.
Dec 15 '09 #12
pradeepjain
563 512MB
okie i did that and it worked ,, i tried to apply some jquery to it .. when its applied it stops working . but without the jquery it works f9!

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 src="jquery.js" type="text/javascript" language="javascript"></script>
  10. <script src="jquery.rating.js" type="text/javascript" language="javascript"></script>
  11.         <link href="jquery.rating.css" type="text/css" rel="stylesheet"/>
  12.  
  13. <script type="text/javascript">
  14. function test(name)
  15. {
  16.     alert(name);
  17.    for (k=1; k<=10; k++){
  18.     document.getElementById(name+k).disabled=false;
  19. }
  20. }
  21. </script>
  22. </HEAD>
  23.  
  24. <BODY>
  25. <?php
  26. for($i = 1; $i <= 15 ; $i++){
  27.  for($k = 1; $k <= 10 ; $k++){
  28.  $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."".$k."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
  29.  }
  30. $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a><br/>";
  31.  }
  32. echo $myresult;
  33.  ?>
  34. </BODY>
  35. </HTML>
and the jquery.rating.js, jquery.rating.css are taken form the below site .

http://www.fyneworks.com/jquery/star.../#tab-Overview
Dec 15 '09 #13
pradeepjain
563 512MB
is there no solution for this or has no1 looked at this problem?
Dec 21 '09 #14
Dormilich
8,658 Expert Mod 8TB
my problem is, that I don’t know jQuery.
Dec 21 '09 #15
pradeepjain
563 512MB
some suggestions for what might be causing problems here.. bcos with out jquery everything works very well. but as soon as jquery is applied and radio buttons are replaced with stars it stops working :I(
Dec 21 '09 #16
Dormilich
8,658 Expert Mod 8TB
I think your code works as intended…

… only that your stars are no radio buttons.

PS. check out the demo page with FireBug, you will see, that all radio buttons are hidden and instead some divs are visible. thus your radio buttons are disabled, but it doesn’t matter.

PPS. what an ‘obvious’ error, *sigh*
Dec 21 '09 #17
drhowarddrfine
7,435 Expert 4TB
all tag names upper case and all attribute names lowercase.
Actually, tag and attribute names are case insensitive in HTML and, nowadays, lowercase is most used.
Dec 21 '09 #18
pradeepjain
563 512MB
@Dormilich
you mean to say that the button thing will not work ! no other work around for this?
Dec 30 '09 #19
Dormilich
8,658 Expert Mod 8TB
the button thing will work, only it doesn’t matter, because the buttons are invisible. to do anything on the stars, you have to meddle with the plugin.
Dec 30 '09 #20

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

Similar topics

1
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...
1
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...
2
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...
2
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...
1
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 ...
6
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...
3
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.