473,396 Members | 2,158 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,396 software developers and data experts.

checkboxes and javascript

First, I am not a programmer, just a hack who tries to make things work

I am trying to process a form using javascript that detects if the user has checked the set as default box and then sets a cookie based on the regional preference. I figured out how to get the values from the radiobuttons, but am stuck on the checkbox value. Here's my form code. Like I said, I just need to know how to retreive the value from the checkbox field.

<form name="form">
<p><b>Select Region</b><br>
<input type="radio" name="group1" value="North America" checked>
North America<br>
<input type="radio" name="group1" value="Europe">
Europe</p>
<p>
<input name="remember" type="checkbox" id="remember" value="yes">
Remember selection<br>
<input type="Button" onClick="MM_callJS('GetDefault')" value="Select">
</p>
</form>
Jan 3 '07 #1
3 3480
First, I am not a programmer, just a hack who tries to make things work

I am trying to process a form using javascript that detects if the user has checked the set as default box and then sets a cookie based on the regional preference. I figured out how to get the values from the radiobuttons, but am stuck on the checkbox value. Here's my form code. Like I said, I just need to know how to retreive the value from the checkbox field.

<form name="form">
<p><b>Select Region</b><br>
<input type="radio" name="group1" value="North America" checked>
North America<br>
<input type="radio" name="group1" value="Europe">
Europe</p>
<p>
<input name="remember" type="checkbox" id="remember" value="yes">
Remember selection<br>
<input type="Button" onClick="MM_callJS('GetDefault')" value="Select">
</p>
</form>

Hi, I don't make a living off of JavaScript, but I think I know the answer to your problem.

First, create an IF statement to check your checkBox. Example like so:

if (docuemnt.formNameHere.remember.checked)
{
---do some code here---
}
else
--- do something else here---


Then, since you want to retrieve the checkBox value, assuming it's a 'true' or 'false', you can create a variable to do so in your IF statement like:

if (...)
{
isChecked.value = 'true';
}
else
isChecked.value = 'false';

I hope that works for you.
Jan 3 '07 #2
acoder
16,027 Expert Mod 8TB
First, I am not a programmer, just a hack who tries to make things work

I am trying to process a form using javascript that detects if the user has checked the set as default box and then sets a cookie based on the regional preference. I figured out how to get the values from the radiobuttons, but am stuck on the checkbox value. Here's my form code. Like I said, I just need to know how to retreive the value from the checkbox field.

<form name="form">
<p><b>Select Region</b><br>
<input type="radio" name="group1" value="North America" checked>
North America<br>
<input type="radio" name="group1" value="Europe">
Europe</p>
<p>
<input name="remember" type="checkbox" id="remember" value="yes">
Remember selection<br>
<input type="Button" onClick="MM_callJS('GetDefault')" value="Select">
</p>
</form>
You shouldn't use "form" for the name of your form to avoid confusion. Also, instead of value="yes", use "checked" instead on its own as follows:
Expand|Select|Wrap|Line Numbers
  1. <input name="remember" type="checkbox" id="remember" checked>
So assuming you've named your form "theForm", you can retrieve the checkbox value as follows:
Expand|Select|Wrap|Line Numbers
  1. var cBoxVal = document.theForm.remember.checked;
cBoxVal will be 'true' or 'false' depending on whether the checkbox has been checked.

Hope that helps.
Jan 3 '07 #3
ronverdonk
4,258 Expert 4TB
If you ever want to pass the W3C XHTML check, you declare your statement as
Expand|Select|Wrap|Line Numbers
  1. <input name="remember" type="checkbox" id="remember" checked="checked" />
Ronald :cool:
Jan 3 '07 #4

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

Similar topics

6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...
0
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...

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.