/    Sign up×
Community /Pin to ProfileBookmark

Checkboxes and onClick

I have a form with a bunch of <select> fields, and each has an onChange=”HandleChange();” and HandleChange is a very simple function that looks like this:

function HandleChange() {
parent.document.location.href=”vendor_ranking_frames.asp?viewAcctMngr=” + document.forms[0].acctMngr.value + “&viewBlahBlah=” + document.forms[0].BlahBlah.value;
}

Except there are several more &viewBlahBlah’s in there because there are lots of <select> fields.

Now, I need to add a checkbox to this form, and I need it to trigger the same HandleChange function. Here is where I’m having trouble. I’ve been using onClick=”HandleChange();” (because onChange doesn’t seem to do it with checkboxes), and it does trigger the function, but it’s not passing the value I want it to pass. By default, the checkbox is unchecked and thus its value is “unchecked”. But when I check it and HandleChange is triggered, it’s still passing “unchecked” through … when I want it to pass its new value, “checked”, through. Incongruous with the <select> fields, which by default are set to value “all” but when I change one to “BS” it passes “BS” through. To further illustrate, here’s exactly what’s going on [edited for length and to fit your screen]:

function HandleChange() {
parent.document.location.href=”vendor_ranking_frames.asp?viewAcctMngr=” + document.forms[0].acctMngr.value + “&viewIS_Filter=” + document.forms[0].IS_Filter.value;
}

<SELECT NAME=”acctMngr” SIZE=”1″ ONCHANGE=”HandleChange();”>
<option value=”all” selected>ALL</option>
<OPTION VALUE=”BS”>BS</OPTION>
</SELECT>

<input type=”checkbox” name=”IS_Filter” value=”unchecked” onClick=”HandleChange();”>

When I make a change to the select dropdown (selecting BS from the default “ALL”), HandleChange is triggered and the address bar looks like this:

vendor_ranking_frames.asp?viewAcctMngr=BS&viewIS_Filter=unchecked

But when I make a change to the checkbox (checking it, from its default of being unchecked), HandleChange is triggered and the address bar looks like this:

vendor_ranking_frames.asp?viewAcctMngr=all&viewIS_Filter=unchecked

What should I do to make it pass “viewIS_Filter=checked” ? Catch my drift? ?

Thanks….

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — instead of onClick use onChecked
Copy linkTweet thisAlerts:
@swoffordauthorNov 09.2005 — Is onChecked a very standard event handler? It doesn't do anything in Firefox when I tried it. (Plus, only 337 hits for it on Google ...)
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — Well, you are using value="unchecked". Make your checkbox look like this:

<input type="checkbox" name="IS_Filter" value="" unchecked onClick="HandleChange();">

Then access it like:

function HandleChange() {

parent.document.location.href="vendor_ranking_frames.asp?viewAcctMngr=" + document.forms[0].acctMngr.value + "&viewIS_Filter=" + document.forms[0].IS_Filter.checked;

}
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — Before you were just storing a value in your checkbox and when it was clicked that value didnt change. The checked property changed.
Copy linkTweet thisAlerts:
@swoffordauthorNov 09.2005 — Ah, yes! Thank you.
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — No problem. You are very welcome.
×

Success!

Help @swofford spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...