473,396 Members | 2,010 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.

passing multiple checkbox variables w/same cb name ?

zig
I've posted this on alt.comp.lang.coldfusion, but is predominantly a
javascript problem:

I have a CF query which returns several rows of records. I wanted to
have a checkbox on each record of that returned query which would
allow the user to select which record to print if checked.

As the checkboxes are generated within the CF, they all have tha same
name. With the help of a fellow a.c.l.c. member, we've got the script
to a point where it will define whether 1 box is checked or not, only
when there are more than 1, I receive the error: 'f.length is null or
not an object'.

Here's the script as it is now. Any help greatly appreciated:
<script language="JavaScript">
function win(){
var s = '';
f = document.boxs;
for (var i=0;i < f.length;i++){
if (f.elements[i].name == 'printprop' && f.elements[i].checked){
if (s.length != 0) s += ',';
s += f.elements[i].value;
}
} window.open("openprintR.cfm?ID=" +
s,"","height=600,width=600,left=0,top=0")
}
</script>

<body>
<a href="javascript:win()">print report</a>

<cfoutput query="myquery">
<form name="boxs" action="javascript:win()" method="post">print this
property&nbsp;<input type="checkbox" name="printprop"
value=#ID#></form>
</cfoutput>
Steve.
Jul 20 '05 #1
12 2933
In article <f7**************************@posting.google.com >,
vi******@btopenworld.com enlightened us with...


Here's the script as it is now. Any help greatly appreciated:


Assumption 1: you want a string "s" with the values of the checked
checkboxes, separated by commas.
Assumption 2: all the checkboxes are named "printprop".

Note that this is the test script, so values are hardcoded and link set
to alert. Change this as needed.

<html>
<head>
<title> New Document </title>
<script language="javascript" type="text/javascript">
function win()
{
var s = '';
f = document.forms["boxs"].elements["printprop"];
if (f.length)
{
for (var i=0;i < f.length;i++)
{
if (f[i].checked)
{
if (s.length != 0) s += ',';
s += f[i].value;
}
}
}
else if (f)
{
s += f.value;
}
alert(s);
}
</script>
</head>

<body>
<a href="#" onClick="win(); return false;">print report</a>

<form name="boxs" action="" method="get">
property 1:<input type="checkbox" name="printprop" value='1'><br>
property 2:<input type="checkbox" name="printprop" value='2'><br>
property 3:<input type="checkbox" name="printprop" value='3'><br>
</form>
</body>
</html>

--
--
~kaeli~
You feel stuck with your debt if you can't budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Kaeli,

first off - thanks for the reply!

OK, I tried your testing script and it works fine with one checkbox, but
I think the problem lies with the fact that I'm having to create the
checkboxes within a coldfusion output table and therefore their
quantities vary dependant upon how many rows are returned.

When there is more than 1 present, I get this error upon submit:

'document.forms.boxs.elements.printprop is null or not an object'
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
Kaeli,

first off - thanks for the reply!

OK, I tried your testing script and it works fine with one checkbox, but
I think the problem lies with the fact that I'm having to create the
checkboxes within a coldfusion output table and therefore their
quantities vary dependant upon how many rows are returned.

When there is more than 1 present, I get this error upon submit:


The test script works just fine with multiples - therefore, the error is
not the script per se.

Let's see your generated HTML - that is, view the source of the page to
see the html output the script is actually working with.

I don't need the whole thing if it's huge - just the form and the
script.

How the html was generated doesn't matter a bit, whether by CF, JSP, or
ASP. The browser sees only html.

--
--
~kaeli~
Never mess up an apology with an excuse.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4
Ah, I see what you're geting at - the form is duplicated by the CF if
more than one row returned, and therefore returns more than one form,
both with the same name + elements:

<---stuff above--->

<form name="boxs" action="" method="get">print this property&nbsp;<input
type="checkbox" name="printprop" value=88></form>

<---stuff inbetween--->

<form name="boxs" action="" method="get">print this property&nbsp;<input
type="checkbox" name="printprop" value=149></form>

<---stuff below--->

so how do you cope with this?
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
Ah, I see what you're geting at - the form is duplicated by the CF if
more than one row returned, and therefore returns more than one form,
both with the same name + elements:

so how do you cope with this?


Change my CF to do it properly. :)

I should have caught this the first time you posted. Sorry. It's been
awhile since I used CF.

Change it to:

<form name="boxs" action="javascript:win()" method="post">print this
property&nbsp;
<cfoutput query="myquery">
<input type="checkbox" name="printprop"
value=#ID#>
</cfoutput>
</form>

--
--
~kaeli~
A man's home is his castle..., in a manor of speaking.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6
sorry, but now I'm getting confused.

You asked to see the html output, but in my CF code the form has to
exist within a larger output [there are many other CF variables above
and below] but all within the same output row. I suppose I could place a
seperate output within the form and continue after, but I'm not sure I
understand what difference that makes.

Would you then be calling on that query with the javascript seperatley?

I don't know if htis helps or confuses matters more, but I saw a similar
feature on a website recently. The designer kindly forwarded the CF code
they used to iterate the form, only I'm not sure how to implement it
into my schema. As you seem to have worked with CF I thought I'd include
it, just in case it's of some use:
<!--- Checks if the Array is Defined and Creates --->
<cfif NOT IsDefined("Session.ReqInfo")>
<cfset Session.ReqInfo=ArrayNew(1)>
</cfif>

<!--- If no information was requested proceed to Request Information
page --->
<cfif NOT IsDefined("Form.Info")>
<cfif left(prevpage,6) IS "detail"><cflocation
url="#variables.prevpage#S"><cfelse><cflocation
url="requestinfo.cfm"></cfif>
</cfif>

<cfset infoarray=ListToArray(#Form.Info#)>

<cfset size=ArrayLen(infoarray)>
<cfset count=ArrayLen(session.reqinfo)>

<!--- Load Array with new Requests --->
<cfloop index="i" from="1" to="#variables.size#">
<cfset count=count+1>
<cfset Session.ReqInfo[#variables.count#]=variables.InfoArray[#i#]>
</cfloop>

<cfif variables.count GT 1>
<!--- Sort Array --->
<cfset temp=ArraySort(Session.ReqInfo, "numeric")>

<!--- Eliminate Duplicates --->
<cfset i=1>
<cfloop condition="i LT count">
<cfset i=i+1>
<cfif i LE #ArrayLen(Session.ReqInfo)#>
<cfif Session.ReqInfo[i] EQ Session.ReqInfo[i-1]>
<cfset temp=ArrayDeleteAt(Session.ReqInfo,i)>
<cfset i=i-1>
</cfif></cfif>
</cfloop>
</cfif>
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
sorry, but now I'm getting confused.

The key is understanding that CF executes on the server and javascript
executes on the client.
The way you had your CF, the loop was creating a separate form each
time.
You asked to see the html output, but in my CF code the form has to
exist within a larger output [there are many other CF variables above
and below] but all within the same output row. I suppose I could place a
seperate output within the form and continue after, but I'm not sure I
understand what difference that makes.

The difference is what the browser sees and the html that is generated.
This example helps illustrate the problem.
There is a very big difference between

1.
var j=0;
var k=0;
for (i=0; i<10; i++)
{
k++;
}
j++;

2.
var j=0;
var k=0;
for (i=0; i<10; i++)
{
k++;
j++;
}

What is happening is that you are doing something in a loop that should
not be in a loop.
Would you then be calling on that query with the javascript seperatley?

The CF query runs on the server and generates html.
The JS runs on the client.
I don't know if htis helps or confuses matters more, but I saw a similar
feature on a website recently. The designer kindly forwarded the CF code
they used to iterate the form, only I'm not sure how to implement it
into my schema. As you seem to have worked with CF I thought I'd include
it, just in case it's of some use:

<snip>

There is no form in that code. That code *processes* a form. BIG
difference.

Just change your original code to my correction (or equivalent) and see
if it helps you.
This was your original:
<a href="javascript:win()">print report</a>

<cfoutput query="myquery">
<form name="boxs" action="javascript:win()" method="post">print this
property&nbsp;<input type="checkbox" name="printprop"
value=#ID#></form>
</cfoutput>
Change it to
<a href="javascript:win()">print report</a>

<form name="boxs" action="javascript:win()" method="post">print this
property&nbsp;
<cfoutput query="myquery">
<input type="checkbox" name="printprop"
value=#ID#>
</cfoutput>
</form>

See how I moved the query so it iterated only for the form elements, not
the form tag?
Your goal is to have only one form tag and one end form tag. The queries
that generate the elements go inside. Any other CF variables that do not
affect the html output make no difference as to placement. They run on
the server and the client doesn't see them.

--
--
~kaeli~
A boiled egg in the morning is hard to beat.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #8
Kaeli,

Thanks for the time you've given to this. I took onboard your
suggestions re the form and moved the <cfoutput> and <form> tags around
and bingo, I now can retrieve the variables as destinct values within a
comma delimeted list.

My sring is now something like:

http://www.,mysite.com/printpage.cfm?ID=10,20,30 etc

My only problem now being how to interprate that list on my printpage. I
have tried SQL statements:

WHERE ID LIKE '#ListFirst(ID)#'

and I've tried

WHERE ID LIKE '#ListRest(ID)#'

but they only return the residual values of their conditions. Do you
know of a way to retrieve ALL of the Lists values?

Thanks,
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #9
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
Kaeli,

Thanks for the time you've given to this. I took onboard your
suggestions re the form and moved the <cfoutput> and <form> tags around
and bingo, I now can retrieve the variables as destinct values within a
comma delimeted list.

My sring is now something like:

http://www.,mysite.com/printpage.cfm?ID=10,20,30 etc


Well, it needs to be url safe. No spaces. No special characters.
I don't know if your real url is b/c I don't remember if a comma is cool
in the url.

To check, in the body (between <body> and </body> html tags) of
printpage (or just a temp CF page with nothing but this to make it
easy), do
<cfif isDefined("url.ID")>
<cfoutput>#url.ID#</cfoutput>
<cfelse>
Arg! No ID!
</cfif>

See if that gets printed as
10,20,30 etc

If it does, change your SQL to

WHERE ID IN (#url.ID#)

assuming ID is a numeric field in the DB, not a string.
If it's a string, you'll have to quote the values. The ID is taken in as
a string, not a list (I believe), so what I would do (assuming CF has no
function for this, which IIRC it does not) is prepend a quote to the
string, run replace on the commas and make them quote, comma, quote,
then append a quote to the end, resulting in
'10','20','30'

HTH
--
--
~kaeli~
Support your local medical examiner: die strangely!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #10
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
WHERE ID LIKE '#ListFirst(ID)#'

and I've tried

WHERE ID LIKE '#ListRest(ID)#'

but they only return the residual values of their conditions. Do you
know of a way to retrieve ALL of the Lists values?


In case I wasn't clear in my other post, the url string is NOT a List. I
know it was a List when you made the url on the first page, but the
printpage doesn't know about that. It sees a url as a querystring. The
commas might make it into a List by default in CF, but technically, it's
a string. So be careful before using List functions.

ListFirst would only get one value, if it were a List. Not much help
there.
LIKE assumes the value is one big string. Putting an entire list in
there wouldn't do much for you. You want IN, not LIKE.
See my other post for more on that.

--
--
~kaeli~
Is it true that cannibals don't eat clowns because they
taste funny?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #11
Kaeli,

You're a star :o)

WHERE ID IN (#url.ID#) - did the trick!

I can't begin to thank you enough for your persistance.
Steve.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #12
In article <40***********************@news.frii.net>,
vi******@btopenworld.com enlightened us with...
Kaeli,

You're a star :o)

WHERE ID IN (#url.ID#) - did the trick!

I can't begin to thank you enough for your persistance.


You're more than welcome.

--
--
~kaeli~
If it's tourist season, why can't we shoot them?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #13

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

Similar topics

7
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
6
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
4
by: ATDave | last post by:
So basically I'm just creating a form that I want the results e-mailed to somebody. I have everything working except for the checkmark sections that can have multiple answers. I'm a newbie when...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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...

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.