473,473 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RadioButtonList

18 New Member
Hi

I have an Evaluation Page
at the end I want to submit this Evaluation

But before that i want to check if every RadioButtonList in the page is checked

How can i do that

shall I do (IF Statement)
but i have 20 Question
so ... i will do for them all !!!!
or there is another way to check them all ??
Feb 20 '08 #1
12 1861
shweta123
692 Recognized Expert Contributor
Hi,

You can try this code

Expand|Select|Wrap|Line Numbers
  1. <script language = "javascript">
  2.  
  3. function CheckRadioList()
  4.  {
  5.   var grp = document.forms[0].elements["BtnList1"];
  6.   var x, len = grp.length;
  7.  for (x=0; x<len; x++) 
  8.    {
  9.     if (!grp[x].checked) break;
  10.     return true;
  11.   }
  12.   if (x < len) 
  13.    {
  14.     window.alert("radio button not checked.");
  15.     return false;
  16.    }
  17.  
  18. </script>
  19.  
Hi

I have an Evaluation Page
at the end I want to submit this Evaluation

But before that i want to check if every RadioButtonList in the page is checked

How can i do that

shall I do (IF Statement)
but i have 20 Question
so ... i will do for them all !!!!
or there is another way to check them all ??
Feb 20 '08 #2
moonalamoor
18 New Member
Than you a lot

i understand the idea

but how can i write this variable

var grp = document.forms[0].elements["BtnList1"];


this is not available
document.forms[0].elements["BtnList1"];

it gives me an error
Feb 20 '08 #3
jeffstl
432 Recognized Expert Contributor
What is the name given to your radio buttons in the form?

You need to make it the same name as referred to in the javascript :-$

<input type=radio name="btnlist1">

If ALL your radio buttons have the same name you will have created an array, which will work with the code given above.

You need to loop through this array in some way shape or form, whether its with javascript or with vbscript using the submitted data from the form.

That is how you can check them all.
Feb 20 '08 #4
markrawlingson
346 Recognized Expert Contributor
Than you a lot

i understand the idea

but how can i write this variable

var grp = document.forms[0].elements["BtnList1"];


this is not available
document.forms[0].elements["BtnList1"];

it gives me an error
Radio buttons are indice based because as jeffstl said they're basically an array of values if all of the buttons have the same object name.
So you have to refer to them by their indice.

document.forms[0].elements['BtnList1'] is just an object, it has no value. To get a value, or whether an item is checked or not, you need to refer to the particular item in the radio list array.

EG:
Expand|Select|Wrap|Line Numbers
  1. document.forms[0].elements['BtnList1'](0).value;
  2. document.forms[0].elements['BtnList1'](0).checked;
  3. //etc
  4. //That will refer specifically to the first radio button within the BtnList1 radio button group and refer to its value and whether it is checked or not, respecively.
  5.  
Save the code below to a new .html file and run it in your browser to get a better feel of this.

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function doCheck(i) {
  3.  alert(document.forms[0].elements['BtnList1'](i).value + ' ' + document.forms[0].elements['BtnList1'](i).checked);
  4. }
  5. </script>
  6. <form name="whatever">
  7. <input type="radio" name="BtnList1" value="0" onclick="doCheck(0)">
  8. <input type="radio" name="BtnList1" value="1" onclick="doCheck(1)">
  9. <input type="radio" name="BtnList1" value="2" onclick="doCheck(2)">
  10. <input type="radio" name="BtnList1" value="3" onclick="doCheck(3)">
  11. <input type="radio" name="BtnList1" value="4" onclick="doCheck(4)">
  12. <input type="radio" name="BtnList1" value="5" onclick="doCheck(5)">
  13. <input type="radio" name="BtnList1" value="6" onclick="doCheck(6)">
  14. </form>
  15.  
Sincerely,
Mark
Feb 20 '08 #5
moonalamoor
18 New Member
Hi
Thank you all I understand what you said and I try it

But I want to use RadioButtonList
Not <input type="radio" name="BtnList1" >

Because my page will be for evaluation
Then for every Quest there is many choises.. so I used RadioButtonList

I tried to do what you tell me.. but I get some error
Becouse I don’t know how to creat an array for RadioButtonList
And do (loop to check them)


OR I must use input type="radio" to use arry ???
Feb 20 '08 #6
markrawlingson
346 Recognized Expert Contributor
Ah i see, so you're using .net - You have to be specific of the technologies you're using. ASP is not asp.net - they are very different and the experts in this forum are proficient with classic asp, we generally know little about .net programming - so you'll find it difficult to get the help you require.

However, I know enough to fake my way around a bit.. so I'll try to give you a hand.

You'll need to do something like: This is of course in Visual Basic.

Expand|Select|Wrap|Line Numbers
  1. Sub CheckRadio(s As Object, e As EventArgs)
  2. If Request.Form("BtnList1") Is Nothing Or Request.Form("BtnList1") = "" Then
  3. YourLabel.Text = "You did not select an item from the radio button list control!"
  4. Else
  5. YourLabel.Text = "You selected the following... " & BtnList1.SelectedIndex.Text
  6. End If
  7. End Sub
  8.  
Yes, you'll have to do that for all of them. Or, you can try something like this but i'm not entirely certain how this will work in .net

Expand|Select|Wrap|Line Numbers
  1. Sub CheckRadio(s As Object, e As EventArgs)
  2.    For Each oItem As Object In Request.Form
  3.       If Request.Form(oItem) Is Nothing Or Request.Form(oItem) = "" Then
  4.          YourLabel.Text = "You did not select an item from the radio button list control!"
  5.       Else
  6.          YourLabel.Text = "You selected the following... " & oItem.SelectedIndex.Text
  7.       End If
  8.    Next
  9. End Sub
  10.  
And call this sub onSubmit. Or if you want to test it try calling it OnClick of the radiolistcontrol to see what you get.

Here is a reference: (look at the displayMessage() Sub)

http://www.w3schools.com/aspnet/show...raylist_radio1

If this still doesn't help.. I will have a mod move this thread to the .net forums where the resident experts there will be able to help you more than we can.

Sincerely,
Mark


Hi
Thank you all I understand what you said and I try it

But I want to use RadioButtonList
Not <input type="radio" name="BtnList1" >

Because my page will be for evaluation
Then for every Quest there is many choises.. so I used RadioButtonList

I tried to do what you tell me.. but I get some error
Becouse I don’t know how to creat an array for RadioButtonList
And do (loop to check them)


OR I must use input type="radio" to use arry ???
Feb 20 '08 #7
moonalamoor
18 New Member
Hi ...

I don't understand what you do :S

but that what i did (as you told me)
and it works :)


<script>
function doCheck() {

var i , ch= -1 ;
for (i=0; i<5 && ch==-1 ; i++)
{
if(document.forms[0].elements['BtnList1'](i).checked)
{
ch=1;
alert("You checked "+document.forms[0].elements['BtnList1'](i).value+" "+ch);
}
else
{
alert("You DON'T checked "+document.forms[0].elements['BtnList1'](i).value+" "+ch);
}
}

if(ch== -1)
{
("warning an exsist (label) by red")
}
}
</script>




what i want know

Q: How to change the (color to red) of label of the question that is unchecked !!
coz labels is undefined in my script !!! i dont't know why??

and what type of script that i have to use according to this script ??


thanks again
Feb 21 '08 #8
markrawlingson
346 Recognized Expert Contributor
I'm not sure how to do this in .net but I'm thinking it's probably something like..

Expand|Select|Wrap|Line Numbers
  1. If Request.Form("BtnList1") Is Nothing Or Request.Form("BtnList1") = "" Then
  2.    LabelControl.Color = 'red'
  3. End If
  4.  
In javascript, it's:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('LabeltocolorRed').style.color = 'red'
  2.  
Sincerely,
Mark

Hi ...

I don't understand what you do :S

but that what i did (as you told me)
and it works :)


<script>
function doCheck() {

var i , ch= -1 ;
for (i=0; i<5 && ch==-1 ; i++)
{
if(document.forms[0].elements['BtnList1'](i).checked)
{
ch=1;
alert("You checked "+document.forms[0].elements['BtnList1'](i).value+" "+ch);
}
else
{
alert("You DON'T checked "+document.forms[0].elements['BtnList1'](i).value+" "+ch);
}
}

if(ch== -1)
{
("warning an exsist (label) by red")
}
}
</script>




what i want know

Q: How to change the (color to red) of label of the question that is unchecked !!
coz labels is undefined in my script !!! i dont't know why??

and what type of script that i have to use according to this script ??


thanks again
Feb 22 '08 #9
moonalamoor
18 New Member
OK ....
i think that i'am using ( asp ) not ( .net ) :S

i'm doing a web site ... with ( HTML)
and script with javascript (as you told me) :)


i used this, coz the first one i didn't understant it

Code: ( javascript ):

document.getElementById('Label1').style.color = 'red'

it works
but the label ... return to black after one second ... I don't know why :S
How can i keep red ... ???



Thank you :)
Feb 22 '08 #10
markrawlingson
346 Recognized Expert Contributor
That's wierd :P

Show your code so we can help determine why it's changing back to black.

Sincerely,
Mark

OK ....
i think that i'am using ( asp ) not ( .net ) :S

i'm doing a web site ... with ( HTML)
and script with javascript (as you told me) :)


i used this, coz the first one i didn't understant it

Code: ( javascript ):

document.getElementById('Label1').style.color = 'red'

it works
but the label ... return to black after one second ... I don't know why :S
How can i keep red ... ???



Thank you :)
Feb 22 '08 #11
moonalamoor
18 New Member
i thing that i want to do some thing in page load :S
i don't know


this is my script code put i put it before ...

Expand|Select|Wrap|Line Numbers
  1. function doCheck() {
  2.  
  3. var i ,j, ch ;
  4.  
  5. for (j=1; j<21 ; j++) 
  6. ch= -1;
  7. for (i=0; i<5 && ch==-1 ; i++) 
  8.   {       
  9.   if(document.forms[0].elements['BtnList'+j](i).checked)
  10.   {
  11.     ch=1;
  12.     alert("You checked "+document.forms[0].elements['BtnList'+j](i).value+" "+ch+"  BtnList"+j);
  13.   }
  14.  else
  15.     {
  16.     alert("You DON'T checked "+document.forms[0].elements['BtnList'+j](i).value+"  "+ch+"  BtnList"+j);
  17.     }
  18.   }
  19.  
  20.   if(ch==-1)
  21.   {
  22.     document.getElementById("Label"+j).style.color= 'red';
  23.     alert("Please answer Question number "+j);
  24.  
  25.   }}}  
Feb 22 '08 #12
moonalamoor
18 New Member
Hi

ummmm

just want to know

how can i control the page loading

coz when the script finish itss jop

the page will reset automatically (i don't want that) .... !!!!

i want to go to another event (on server_side) after an event (on_client side) finish successfully .... so how can i do that ???
Feb 29 '08 #13

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

Similar topics

3
by: Tapi | last post by:
Hello there, I am new to ASP .NET and am tryimg to create a RadioButtonList dynamically. My code below gives an "Index was out of range" error. Where am I going wrong?
6
by: Hazzard | last post by:
I store radiobuttonlist values in the db using the string value of the radio button item value. (nvarchar) I am creating an edit functionality on the asp.net form so that when I reuse my...
3
by: William LaMartin | last post by:
If I create a RadioButtonList with, say, two items, then after the page loads and I select one of the items and then click on a button whose click event contains some code to display the...
5
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 --...
6
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and...
4
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater...
4
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The...
5
by: Øyvind Isaksen | last post by:
I'm making a page to update articles. When a radiobuttonlist is displayed, I want the stored value to be displayed as default (checked). Example: I use a procedure to display the...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hallo, I have a radiobuttonlist control that is added on a custom Web User Control. This control has a property that exposes the SelectedIndex property of the embedded radiobuttonlist. When...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.