473,626 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkbox value

Ron
I have an HTML page, that calls an ASP javascript page on "Submit".
Everything works correctly except that I can't get the value of the
checkboxes. I've been trying code like this:

var s = "Off"
if (Request.Form(" EmailCbx").Chec ked == true)
{s = Request.Form("E mailCbx").name}

No matter what I do (I've tried several other things too) the value always
returns as "Off" What am I doing wrong?

Also, is there some way to get values from all my checkboxes that are
checked?
Feb 24 '06 #1
7 2225
Ron wrote:
I have an HTML page, that calls an ASP javascript page on "Submit".
Everything works correctly except that I can't get the value of the
checkboxes. I've been trying code like this:

var s = "Off"
if (Request.Form(" EmailCbx").Chec ked == true)
What does - Request.Form("E mailCbx") - return?

{s = Request.Form("E mailCbx").name}

No matter what I do (I've tried several other things too) the value always
returns as "Off" What am I doing wrong?
If - Request.Form("E mailCbx") - returns a reference to a checkbox then
it will have a 'checked' property (note the capitalisation) .

You don't have to explicitly test against 'true'. The checked
property's value is a boolean:

if ( Request.Form("E mailCbx").check ed ) {
// it's checked
}


Also, is there some way to get values from all my checkboxes that are
checked?


Yes. Loop through all of them and test their checked property. If it's
true, get the checkbox's value. Supposing 'formA' is the name of your
form, then:

var el, els = document.forms['formA'].elements;
for (var i=0, len=els.length; i<len; ++i){
el = els[i];
if ('checkbox' == el.type && el.checked){
// el is a reference to a checked checkbox
alert('Checkbox ' + el.name + ' is checked');
}
}


--
Rob
Feb 24 '06 #2
Ron
Thanks Rob, this will be very helpful, but the code still isn't working.
Here's what I tried:

var s = "Off"
if (Request.Form(" EmailCbx").Chec ked)
{s = Request.Form("E mailCbx").name}

Maybe this is a good clue. When I try this:

alert(Request.F orm("SoftwareCb x").name);

I get an error: "Object expected" on that line. Does that mean anything
important?
"RobG" <rg***@iinet.ne t.au> wrote in message
news:Bs******** *********@news. optus.net.au...
Ron wrote:
I have an HTML page, that calls an ASP javascript page on "Submit".
Everything works correctly except that I can't get the value of the
checkboxes. I've been trying code like this:

var s = "Off"
if (Request.Form(" EmailCbx").Chec ked == true)


What does - Request.Form("E mailCbx") - return?

{s = Request.Form("E mailCbx").name}

No matter what I do (I've tried several other things too) the value
always returns as "Off" What am I doing wrong?


If - Request.Form("E mailCbx") - returns a reference to a checkbox then
it will have a 'checked' property (note the capitalisation) .

You don't have to explicitly test against 'true'. The checked property's
value is a boolean:

if ( Request.Form("E mailCbx").check ed ) {
// it's checked
}


Also, is there some way to get values from all my checkboxes that are
checked?


Yes. Loop through all of them and test their checked property. If it's
true, get the checkbox's value. Supposing 'formA' is the name of your
form, then:

var el, els = document.forms['formA'].elements;
for (var i=0, len=els.length; i<len; ++i){
el = els[i];
if ('checkbox' == el.type && el.checked){
// el is a reference to a checked checkbox
alert('Checkbox ' + el.name + ' is checked');
}
}


--
Rob

Feb 24 '06 #3
Ron wrote:
Thanks Rob, this will be very helpful, but the code still isn't working.
Please don't top post. Trim quotes and put replies immediately below
the quote they refer to.

Here's what I tried:

var s = "Off"
if (Request.Form(" EmailCbx").Chec ked)
{s = Request.Form("E mailCbx").name}
As I said previously, find out what - Request.Form("E mailCbx") -
returns. Insert the following immediately before the 'if' statement and
report what happens:
alert( typeof Request ); // 'function' or 'object' ?
alert( typeof Request.Form ); // 'function' or 'object' ?
var x = Request.Form('E mailCbx');
alert( typeof x ); // 'object' ?
alert( x.name ); // 'EmailCbx' ?
return;
If any of the above returns - undefined - or gives something
unexpected, then that is your problem (or at least part of it).

Maybe this is a good clue. When I try this:

alert(Request.F orm("SoftwareCb x").name);

I get an error: "Object expected" on that line. Does that mean anything
important?


Yes. It means an object was expected but one wasn't returned. However,
without a bit more information or debugging I can't tell what it was
expected an object but didn't get one. There may also be more errors
after that point.

[...]

--
Rob
Feb 24 '06 #4
Ron wrote:
Thanks Rob, this will be very helpful, but the code still isn't
working. Here's what I tried:
var s = "Off"
if (Request.Form(" EmailCbx").Chec ked)
{s = Request.Form("E mailCbx").name}


I think Rob missed the point that this is ASP javascript. Meaning,
server-side. Right?

If that's true, then the .checked and .name properties won't exist.
If you have this:

<input type="checkbox" name="EmailCbx" value="Yes">

then if it's checked, Request.Form("E mailCbx") will contain "Yes".
If it's not checked, then it won't be submitted at all, and
Request.Form("E mailCbx") will be null or empty.
(I'm not sure about ASP/javascript specifics, since I've never used it)

Hope that helps.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 24 '06 #5
Ron
Insert the following immediately before the 'if' statement and
report what happens:
alert( typeof Request ); // 'function' or 'object' ?
alert( typeof Request.Form ); // 'function' or 'object' ?
var x = Request.Form('E mailCbx');
alert( typeof x ); // 'object' ?
alert( x.name ); // 'EmailCbx' ?
return;

I added the code after the if statement. When I try to tun it, it stops on
the "return" with a message:

Microsoft JScript compilation error '800a03fa'
'return' statement outside of function

/sendmail.asp, line 23

return;
Feb 24 '06 #6
Matt Kruse wrote:
Ron wrote:
Thanks Rob, this will be very helpful, but the code still isn't
working. Here's what I tried:
var s = "Off"
if (Request.Form(" EmailCbx").Chec ked)
{s = Request.Form("E mailCbx").name}

I think Rob missed the point that this is ASP javascript. Meaning,
server-side. Right?


Aggggh. I assumed a Request object had been implemented client-side and
that is what was being called.

[...]
--
Rob
Feb 24 '06 #7
Ron
Matt,

Thank you very much! That was the problem. Thanks to Rob too.

"Matt Kruse" <ne********@mat tkruse.com> wrote in message
news:dt******** @news2.newsguy. com...
Ron wrote:
Thanks Rob, this will be very helpful, but the code still isn't
working. Here's what I tried:
var s = "Off"
if (Request.Form(" EmailCbx").Chec ked)
{s = Request.Form("E mailCbx").name}


I think Rob missed the point that this is ASP javascript. Meaning,
server-side. Right?

If that's true, then the .checked and .name properties won't exist.
If you have this:

<input type="checkbox" name="EmailCbx" value="Yes">

then if it's checked, Request.Form("E mailCbx") will contain "Yes".
If it's not checked, then it won't be submitted at all, and
Request.Form("E mailCbx") will be null or empty.
(I'm not sure about ASP/javascript specifics, since I've never used it)

Hope that helps.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

Feb 24 '06 #8

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

Similar topics

4
4627
by: Jay | last post by:
Hi everybody ! I am currently writing a webpage that displays a list of records ( each record has a checkbox associated with it) to allow users to select any record they want to delete (much like in "hotmail" or "yahoo" e-mail where u can select particular message to delete) ? Anybody have any idea how to do it ? And one more question, I like to write my page so that when the user
4
4624
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input type="checkbox" name="chk_Complete" value="<%Response.Write l_IsChecked%>"<%if cbool(l_IsChecked) then Response.Write " checked"%>> The code to captures the checkbox value in the asp page that builds the sql string is follows
4
3388
by: feanor | last post by:
I need to select children checkboxes when selecting the parent one. This is my function: function SelectChildrens(checkbox_name){ form = document.forms; Sname = checkbox_name.split("-"); for (i=0;i<form.elements.length;i++){ THATname = form.elements.name.split("-"); if (Sname.length==1){ if (THATname==Sname){
5
9567
by: _andrea.l | last post by:
I have n checkboxes and 1 checkbox 'SELECT ALL'. for example: <form action="" method="get"> <input name="sa" type="checkbox" value="v"> select all <input name="c1" type="checkbox" value="v"> option 1 <input name="c2" type="checkbox" value="v"> option 2 <input name="c3" type="checkbox" value="v"> option 3 .... <input name="cn" type="checkbox" value="v"> option n </form>
34
3780
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
6
10400
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to group by using a two dimensional array. <form name=msgs>
0
4091
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
0
3102
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
3
5300
realin
by: realin | last post by:
Hiya all, i am in deep trouble, i thought it was an easy task, but now its getting on my nerves. Well i have a div on a form, which contains a number of checkboxes, as <div class="modalData" id="multipleCommSelect" style="padding: 50px;"> <center>Please select the communities from the list below:<br></center> <label><input name="CommID" value="3" type="checkbox">AIDS</label><br>
1
1847
Death Slaught
by: Death Slaught | last post by:
I play a game that when your backpack fills with items (the limit is 45) you must choose items to discard by unchecking their box. This is very annoying and time consuming so I was wondering if it were possible to create a Javascript function to be saved as a bookmark, and when used it prompts for the checkbox to start at (so it won't discard items that I want to keep) and discards all items after that point. So my main question is, is it...
0
8259
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
8192
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
8637
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...
0
8502
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
6119
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
5571
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();...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
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.