Running Javascript Command from toolbar

C

chadlupkes

I'm working with an internal website with a form with a bunch of
checkboxes indicating records that I need to work with. Part of my job
is printing all those records, meaning I need to check each box that I
want to print. I'd like to do it all at once, but I don't have access
to the code of the website, and they won't add a simple javascript
button that will do this.

So, I want to create a javascript command on my IE toolbar that will
run through the browser window and check all the boxes on the form. Is
this possible? If so, how?

Chad Lupkes
Seattle
 
V

VK

So, I want to create a javascript command on my IE toolbar that will
run through the browser window and check all the boxes on the form. Is
this possible? If so, how?

Would you compromize for an item in your Favorites? In such case you
could use bookmarklet.

Copy the code below and save as HTML page. Open in your browser, right
click on "Check all" link and choose "Add to Favorites" ("Bookmark this
link" or however it's called in your UA). In IE you will get security
warning: click OK.

Now simply choose "Check all" bookmark any time you need it. Please not
that this code is very "greedy": it will check on whatever is
"checkable" on the current page. If it's too much, readjust the
algorithm and replace the bookmarlet with the new code.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" action="">
<input type="checkbox" name="checkbox1" value="checkbox">
<input type="checkbox" name="checkbox2" value="checkbox">
<input type="checkbox" name="checkbox3" value="checkbox">
</form>

<p><a href="
javascript:function checkAll() {
var elm = document.getElementsByTagName('input');
var len = elm.length;
for (var i=0; i<len; ++i) {
if ('checked' in elm) {
elm.checked = true;
}
}
}
void checkAll();
">Check all</a></p>

</body>
</html>
 
C

chadlupkes

That worked!

Thanks!

Chad
So, I want to create a javascript command on my IE toolbar that will
run through the browser window and check all the boxes on the form. Is
this possible? If so, how?

Would you compromize for an item in your Favorites? In such case you
could use bookmarklet.

Copy the code below and save as HTML page. Open in your browser, right
click on "Check all" link and choose "Add to Favorites" ("Bookmark this
link" or however it's called in your UA). In IE you will get security
warning: click OK.

Now simply choose "Check all" bookmark any time you need it. Please not
that this code is very "greedy": it will check on whatever is
"checkable" on the current page. If it's too much, readjust the
algorithm and replace the bookmarlet with the new code.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" action="">
<input type="checkbox" name="checkbox1" value="checkbox">
<input type="checkbox" name="checkbox2" value="checkbox">
<input type="checkbox" name="checkbox3" value="checkbox">
</form>

<p><a href="
javascript:function checkAll() {
var elm = document.getElementsByTagName('input');
var len = elm.length;
for (var i=0; i<len; ++i) {
if ('checked' in elm) {
elm.checked = true;
}
}
}
void checkAll();
">Check all</a></p>

</body>
</html>
 
C

chadlupkes

Ok, it did work, however it's affecting form elements besides the check
boxes, and causing the site to act strange. Here's the code for the
checkboxes:

<INPUT type="checkbox" id="chkProcess" class="Data" title='Check to
select this item.' onchange="SetHidden(this,
document.all('hidProcess'))">

I don't know what the hidProcess is or what it does. My guess is that
it affects the POST command somehow, but that's over my head.

All of them are the same. Is there another dHTML element that I could
reference, preferrably ID or referencing the type="checkbox"?

Chad
So, I want to create a javascript command on my IE toolbar that will
run through the browser window and check all the boxes on the form. Is
this possible? If so, how?

Would you compromize for an item in your Favorites? In such case you
could use bookmarklet.

Copy the code below and save as HTML page. Open in your browser, right
click on "Check all" link and choose "Add to Favorites" ("Bookmark this
link" or however it's called in your UA). In IE you will get security
warning: click OK.

Now simply choose "Check all" bookmark any time you need it. Please not
that this code is very "greedy": it will check on whatever is
"checkable" on the current page. If it's too much, readjust the
algorithm and replace the bookmarlet with the new code.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" action="">
<input type="checkbox" name="checkbox1" value="checkbox">
<input type="checkbox" name="checkbox2" value="checkbox">
<input type="checkbox" name="checkbox3" value="checkbox">
</form>

<p><a href="
javascript:function checkAll() {
var elm = document.getElementsByTagName('input');
var len = elm.length;
for (var i=0; i<len; ++i) {
if ('checked' in elm) {
elm.checked = true;
}
}
}
void checkAll();
">Check all</a></p>

</body>
</html>
 
V

VK

chadlupkes said:
Ok, it did work, however it's affecting form elements besides the check
boxes, and causing the site to act strange. Here's the code for the
checkboxes:

<INPUT type="checkbox" id="chkProcess" class="Data" title='Check to
select this item.' onchange="SetHidden(this,
document.all('hidProcess'))">

I don't know what the hidProcess is or what it does. My guess is that
it affects the POST command somehow, but that's over my head.

All of them are the same. Is there another dHTML element that I could
reference, preferrably ID or referencing the type="checkbox"?

That's getting shaky as I don't know neither what does SetHidden do.
"document.all" usage suggests a pure coding so whatever it does - it
can besides be done in some "creative" way. Without holding any
responsability, try first to change bookmarklet to:

javascript:function checkAll() {
var elm = document.getElementsByTagName('input');
var len = elm.length;
for (var i=0; i<len; ++i) {
if (('checked' in elm) && (elm.className == 'Data')) {
elm.checked = true;
}
}
}
void checkAll();


also you can try to override listeners:

javascript:function checkAll() {
var loophole = new Function();
var tmp = null;
var elm = document.getElementsByTagName('input');
var len = elm.length;
for (var i=0; i<len; ++i) {
if (('checked' in elm) && (elm.className == 'Data')) {
tmp = elm.onchange;
elm.onchange = loophole;
elm.checked = true;
elm.onchange = tmp;
}
}
}
void checkAll();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top