I've posted this on alt.comp.lang.c oldfusion, 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="JavaS cript">
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("op enprintR.cfm?ID =" +
s,"","height=60 0,width=600,lef t=0,top=0")
}
</script>
<body>
<a href="javascrip t:win()">print report</a>
<cfoutput query="myquery" >
<form name="boxs" action="javascr ipt:win()" method="post">p rint this
property < input type="checkbox" name="printprop "
value=#ID#></form>
</cfoutput>
Steve. 12 2977
In article <f7************ **************@ posting.google. com>, vi******@btopen world.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="javas cript" 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
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!
In article <40************ ***********@new s.frii.net>, vi******@btopen world.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
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">pr int this property < input
type="checkbox" name="printprop " value=88></form>
<---stuff inbetween--->
<form name="boxs" action="" method="get">pr int this property < 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!
In article <40************ ***********@new s.frii.net>, vi******@btopen world.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="javascr ipt:win()" method="post">p rint this
property
<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
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("Sess ion.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"><cfloc ation
url="#variables .prevpage#S"><c felse><cflocati on
url="requestinf o.cfm"></cfif>
</cfif>
<cfset infoarray=ListT oArray(#Form.In fo#)>
<cfset size=ArrayLen(i nfoarray)>
<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.coun t#]=variables.Info Array[#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(Sessi on.ReqInfo)#>
<cfif Session.ReqInfo[i] EQ Session.ReqInfo[i-1]>
<cfset temp=ArrayDelet eAt(Session.Req Info,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!
In article <40************ ***********@new s.frii.net>, vi******@btopen world.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="javascrip t:win()">print report</a>
<cfoutput query="myquery" >
<form name="boxs" action="javascr ipt:win()" method="post">p rint this
property < input type="checkbox" name="printprop "
value=#ID#></form>
</cfoutput>
Change it to
<a href="javascrip t:win()">print report</a>
<form name="boxs" action="javascr ipt:win()" method="post">p rint this
property
<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
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!
In article <40************ ***********@new s.frii.net>, vi******@btopen world.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 students on the screen at the same
time, modify some, mark some for deletion and even have blank fields at the
end to add a new record.
In HTML which is generated I label each row and input field with a
name/number combination i.e <input type=text...
|
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: Hunter_69. Here is what the form
looks like. I have the difficulty of inserting the multiple items selected
by the user the first time he visits and uses the screen and then using an
UPDATE when he visits later.
Model | Original Price | Reduced Price...
|
by: PT |
last post by:
I got a problem. And thats.....
First of all, I got these three tables.
------------------- ------------------ ----------------------
tblPerson tblPersonSoftware tblSoftware
------------------- ------------------ ----------------------
PID PName PID* SID* SID SWName
--- ----- --- --- --- ------
1 Thomas 1 1 ...
|
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 dosent meet these requirments an error
message will be displayed. I have pasted the code (and highlighted the
relevant parts) below in the hope that someone can help me out with this.
Ive been trying to suss it out all week & it's driving me nuts!...
|
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, radio, checkbox, and dropdown.
When the form Submit button is clicked, I then need the input data either
written to another location on the same page, or written to another page (a
different frame would be fine)
| |
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);
|
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' name='cbtype' value='3'>
I'm wanting to re-display the same checkboxes, but if the user
previously checked one of them then I want it automatically checked on
|
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 it comes
to PHP, so please be easy :)
So to show an example:
<input type="checkbox" name="SelfDevelopmentInterest" class="other"
value="Self Confidence" />
<label class="left">Self Confidence</label<br />
|
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.
what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly.
Currently this is what it does
serial information 1
parts 1
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |