Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2004, 09:29 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Has checkbox been checked or unchecked?

I am trying to determine if the user has checked or unchecked a checkbox, the following code always seems to be running the else condition:

    var mssge
    function testing(catId)
    {
       for (i=0; i < eventCategories.length; ++i)
       {
          if (eventCategories[i].checked)
          {
             mssge = ("you have checked : " + catId);
          }
          else
          {
             mssge = ("you have unChecked : " + catId);
          }

       }
       alert (mssge);
    }


<input type="checkbox" name="eventCategories" onClick="testing(<%= intVal %>);">

TYIA your help is appreciated

Wind is your friend
Matt
__________________
Wind is your friend
Matt
 
Old December 7th, 2004, 10:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

try :

var mssge
function testing(catId)
{
    // look at the current state of the checkbox eventCategories
    if (document.myForm.eventCategories.checked)
    {
        mssge = ("you have Checked : " + catId);
    }
    else
    {
        mssge = ("you have unChecked : " + catId);
    }

}

alert (mssge);


not sure where the array comes from, do you have multiple checkboxes with the same name ?
 
Old December 7th, 2004, 10:21 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Greg

Thank you for your prompt reply

Yes there are multiple checkboxes with the same name. The way the page is set up I would like to post a commer delimited string to the destination page (All the checkboxes have dynamic values)

I have been at this all morning. I am starting to believe my objective isnt all that strait forward, of course of they had unique names it would be.

Thank you again, I am looing forward to finding out if this is possible

Wind is your friend
Matt
 
Old December 7th, 2004, 10:24 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

In addition, your function was appreciated but did not do the trick.

My function now looks like this (always seems to be running the if condition):

    var mssge
    var checked = false;
    function testing(catId)
    {
       for (var i=0; i < editEvent.eventCategories.length; i++)
       {
          if(editEvent.eventCategories[i].checked == true)
          {
             checked = true;
             mssge = ("you have checked : " + catId);
             break;
          }
          else if(!checked)
          {
             mssge = ("you have unChecked : " + catId);
          }

       }
       alert (mssge);
    }


Wind is your friend
Matt
 
Old December 8th, 2004, 12:38 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

solution:

<input type="checkbox" onClick="testing(this,<%= getSecond(0) %>);"...

function testing(oneelement, catId)
{
var status = 'unChecked';

if (oneelement.checked)
{
status = 'checked';
alert('You have ' + status + ': ' + catId);
}
else
{
alert('You have ' + status + ': ' + catId);
}

Yes, I'm still freaking out about thee not being a for loop in there. The problem got solved at:
http://www.tek-tips.com/viewthread....d=964029&page=1

Have a fine day

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox checked all mateenmohd Javascript 1 January 2nd, 2007 06:19 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Checkbox checked? ninel ASP.NET 2.0 Professional 1 April 12th, 2006 10:50 PM
Resetting Checkbox back to UNCHECKED savoym C# 3 July 21st, 2004 01:41 PM
allow only one checkbox to be checked! morpheus HTML Code Clinic 5 April 15th, 2004 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.