esbesb
asked on
Reading cfselect variables (selected or in total) after form submitted
Hi
I have two cfselects - the left side is the only one the user sees if they have javascript disabled.
It is populated from a query - with say 2 pre-selected values, but they can change the selection and I need to loop the cfselect (called "IntergroupIDs:) for their new choices.
The second cfselect sits on the lright - called "connectedIntergroups" (and thru javascript takes the selections from the left cfselect. Then when the form is posted - if javascruipt is on - I need to loop the right-hand cfselect for all the values in it.
I have tried cfloop, simply Form.IntergroupIDs - but no luck. Also values are multiple.
Any clues?
Many thanks
full set up code below
<cfset selected_IDS = valuelist(qryIntergroupMee tings.Inte rgroupID)>
<cfselect name = "IntergroupID" multiple="yes">
<option value = 0>Click to Select Intergroups</option>
<option value = 0>------------------------ ---------- ---</optio n>
<cfloop query="qryIntergroupList">
<cfoutput><option <cfif listfind(selected_IDS, qryIntergroupList.Intergro upID)>sele cted</CFIF > value = IntergroupID#>#IntergroupN ame#</opti on></cfout put>
</cfloop>
</cfselect>
<SCRIPT language="JavaScript" type="text/javascript">
document.write('<input type="button" name="Connect" value=">> Add" size=1 onclick="connectIntergroup s();"> <br> <br>');
document.write('<input type="button" name="Disconnect" value="<< Remove" size=1 onclick="disconnectIntergr oups();"> <br>');
</SCRIPT>
<noscript>selection on left<br>will overwrite the right side</noscript>
<cfselect name = "connectedIntergroups" multiple="yes" size="11">
<cfoutput query = "qryIntergroupMeetings">
<option value = #IntergroupID#>#Intergroup Name#</opt ion>
</cfoutput>
</cfselect>
I have two cfselects - the left side is the only one the user sees if they have javascript disabled.
It is populated from a query - with say 2 pre-selected values, but they can change the selection and I need to loop the cfselect (called "IntergroupIDs:) for their new choices.
The second cfselect sits on the lright - called "connectedIntergroups" (and thru javascript takes the selections from the left cfselect. Then when the form is posted - if javascruipt is on - I need to loop the right-hand cfselect for all the values in it.
I have tried cfloop, simply Form.IntergroupIDs - but no luck. Also values are multiple.
Any clues?
Many thanks
full set up code below
<cfset selected_IDS = valuelist(qryIntergroupMee
<cfselect name = "IntergroupID" multiple="yes">
<option value = 0>Click to Select Intergroups</option>
<option value = 0>------------------------
<cfloop query="qryIntergroupList">
<cfoutput><option <cfif listfind(selected_IDS, qryIntergroupList.Intergro
</cfloop>
</cfselect>
<SCRIPT language="JavaScript" type="text/javascript">
document.write('<input type="button" name="Connect" value=">> Add" size=1 onclick="connectIntergroup
document.write('<input type="button" name="Disconnect" value="<< Remove" size=1 onclick="disconnectIntergr
</SCRIPT>
<noscript>selection on left<br>will overwrite the right side</noscript>
<cfselect name = "connectedIntergroups" multiple="yes" size="11">
<cfoutput query = "qryIntergroupMeetings">
<option value = #IntergroupID#>#Intergroup
</cfoutput>
</cfselect>
Hi,
If you submit the form the items in the selectbox must be selected to submit
else there is no Form.IntergroupIDs
here is some code you can use to select the values:
so <form .... onsubmit="selectall()";>
function selectall()
{
totalOption = document.formname.selectna me.options .length
for (X = 0; X < AantalOpties; X++)
document.formsname.selectn ame.option s[X].selec ted = true
}
Mause
If you submit the form the items in the selectbox must be selected to submit
else there is no Form.IntergroupIDs
here is some code you can use to select the values:
so <form .... onsubmit="selectall()";>
function selectall()
{
totalOption = document.formname.selectna
for (X = 0; X < AantalOpties; X++)
document.formsname.selectn
}
Mause
ASKER
Got that - Say the selected values are intergroups that the user is saying they want to be connected to that meeting
If one or more are selected and form is posted
how can I loop the selected intergroup values to use them individually
i.e. say 2,8,10 are selected
then I need to query the database for each of the 3 intergroup values to say if there is a record connecting the meeting and the intergroup - if not insert one.
So the Form.IntergroupID (after submission) is 2,8,10
How can I make it
2
8
10
The valueList only works with queries not form variables. Maybe an array - what is the length of a cfselect?
Also for the none selected cfselect (which holds the connections the database already has - i.e. user doesn't select really) - how can I loop that regardless of whether it's selected - i.e. after posting I presume there will be no Form.connectedIntergroups?
thanks
If one or more are selected and form is posted
how can I loop the selected intergroup values to use them individually
i.e. say 2,8,10 are selected
then I need to query the database for each of the 3 intergroup values to say if there is a record connecting the meeting and the intergroup - if not insert one.
So the Form.IntergroupID (after submission) is 2,8,10
How can I make it
2
8
10
The valueList only works with queries not form variables. Maybe an array - what is the length of a cfselect?
Also for the none selected cfselect (which holds the connections the database already has - i.e. user doesn't select really) - how can I loop that regardless of whether it's selected - i.e. after posting I presume there will be no Form.connectedIntergroups?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great - got the non script processing for the selected on a post back
but how can I loop all the values of the second cfselect (when they will be unselected) when script is enabled?
code as below for the nonscript - plus how do you ensure this non-script does not run when the script runs (as it seems to be running regardless)
<script>
<!---this is where I need help - connectedIntergroups are unselected values--->
<cfloop index="i" from="1" to="#ArrayLen(Form.connect edIntergro ups)#" step="1">
????????????????????
do inserts and deletes
</cfloop>
</script>
<noscript>
<!---procesing from right side box - only if no script--->
<cfquery NAME="qryFindConnectedInte rgroups" DATASOURCE= "#Meetings#">
SELECT * FROM IntergroupMeetings
where MeetingID = #MeetingID#
</cfquery>
<cfif #qryFindConnectedIntergrou ps.Recordc ount# neq 0>
<cfset connected_IDS = valuelist(qryFindConnected Intergroup s.Intergro upID)>
</cfif>
<cfloop index="SELECTED_ID" list="#Form.IntergroupID#" >
<cfif #SELECTED_ID# neq 0>
<!---adds intergroups if they are not there already--->
<cfif listfind(connected_IDS, Selected_ID) eq 0>
<cfquery NAME="insertIntergroupConn ection" DATASOURCE= "#Meetings#">
Insert into IntergroupMeetings
(
IntergroupID,
MeetingID,
LastUpdated,
LastUpdatedBy
)
VALUES
(
#Selected_ID#,
#MeetingID#,
Now(),
'#SESSION.Auth.UserName#'
)
</cfquery>
</cfif>
</cfif>
</cfloop>
<cfquery NAME="qryFindConnectedInte rgroups" DATASOURCE= "#Meetings#">
SELECT * FROM IntergroupMeetings
where MeetingID = #MeetingID#
</cfquery>
<cfif #qryFindConnectedIntergrou ps.Recordc ount# neq 0>
<cfset connected_IDS = valuelist(qryFindConnected Intergroup s.Intergro upID)>
</cfif>
<!---remove the ones connected that are not re-selected--->
<cfloop index="conn_ID" list="#connected_IDS#">
<cfif listfind(Form.IntergroupID , conn_ID) eq 0>
<cfquery NAME="deleteIntergroupConn ection" DATASOURCE= "#Meetings#">
Delete from IntergroupMeetings
where
MeetingID = #MeetingID#
and IntergroupID = #conn_ID#
</cfquery>
</cfif>
</cfloop>
</noscript>
many thanks
but how can I loop all the values of the second cfselect (when they will be unselected) when script is enabled?
code as below for the nonscript - plus how do you ensure this non-script does not run when the script runs (as it seems to be running regardless)
<script>
<!---this is where I need help - connectedIntergroups are unselected values--->
<cfloop index="i" from="1" to="#ArrayLen(Form.connect
????????????????????
do inserts and deletes
</cfloop>
</script>
<noscript>
<!---procesing from right side box - only if no script--->
<cfquery NAME="qryFindConnectedInte
SELECT * FROM IntergroupMeetings
where MeetingID = #MeetingID#
</cfquery>
<cfif #qryFindConnectedIntergrou
<cfset connected_IDS = valuelist(qryFindConnected
</cfif>
<cfloop index="SELECTED_ID" list="#Form.IntergroupID#"
<cfif #SELECTED_ID# neq 0>
<!---adds intergroups if they are not there already--->
<cfif listfind(connected_IDS, Selected_ID) eq 0>
<cfquery NAME="insertIntergroupConn
Insert into IntergroupMeetings
(
IntergroupID,
MeetingID,
LastUpdated,
LastUpdatedBy
)
VALUES
(
#Selected_ID#,
#MeetingID#,
Now(),
'#SESSION.Auth.UserName#'
)
</cfquery>
</cfif>
</cfif>
</cfloop>
<cfquery NAME="qryFindConnectedInte
SELECT * FROM IntergroupMeetings
where MeetingID = #MeetingID#
</cfquery>
<cfif #qryFindConnectedIntergrou
<cfset connected_IDS = valuelist(qryFindConnected
</cfif>
<!---remove the ones connected that are not re-selected--->
<cfloop index="conn_ID" list="#connected_IDS#">
<cfif listfind(Form.IntergroupID
<cfquery NAME="deleteIntergroupConn
Delete from IntergroupMeetings
where
MeetingID = #MeetingID#
and IntergroupID = #conn_ID#
</cfquery>
</cfif>
</cfloop>
</noscript>
many thanks
ASKER
So my problem is since nothing is selected - when the form posted there are no values to loop to do similiar inserts
On submit I could do a javascript function but how can I use the cfquery within javascript?
for (var idx3=0; idx3 < document.frmSearch.connect edIntergro ups.length ; idx3 ++)
{
<cfquery NAME="insertIntergroupConn ection" DATASOURCE= "#Meetings#">
Insert into IntergroupMeetings
(
IntergroupID,
MeetingID,
LastUpdated,
LastUpdatedBy
)
VALUES
(
document.frmSearch.connect edIntergro ups.option s[idx3].va lue,
#MeetingID#,
Now(),
'#SESSION.Auth.UserName#'
)
</cfquery>
}
On submit I could do a javascript function but how can I use the cfquery within javascript?
for (var idx3=0; idx3 < document.frmSearch.connect
{
<cfquery NAME="insertIntergroupConn
Insert into IntergroupMeetings
(
IntergroupID,
MeetingID,
LastUpdated,
LastUpdatedBy
)
VALUES
(
document.frmSearch.connect
#MeetingID#,
Now(),
'#SESSION.Auth.UserName#'
)
</cfquery>
}
I wonder if u had a look at my post ... did u see what that tag does & how it cld help u.
Unless i have completely misunderstood ur requirement & suggested something silly :(
Unless i have completely misunderstood ur requirement & suggested something silly :(
Esbesb you cant use ColdFusion in javascript because javascript is client side and coldfusion is serverside language!
So when you want multiple inserts you have to use the cfloop and loop over the list you get from the selectbox
Hope you understand what I mean
Mause
So when you want multiple inserts you have to use the cfloop and loop over the list you get from the selectbox
Hope you understand what I mean
Mause
ASKER
Yes I know - I just meant becasue nothing is selected in the cfselect connectedIntergroups - I would have to interact with javascript storing them before the page is posted.
At the moment I have a very clumsy method of 13 hidden fields - which javascript fills and emptys on the change event. Not finished (or working) - but can you advise - how do you loop an input called text_aVariableNumber in javascript so I don't have all these if statements? Surely there is a better way of coding this. And what happens when you have far more than 13 possibilities?
<!---on the form create 13 text boes (to be hidden)--->
<cfloop index="i" from="1" to="13">
<input type="text" name=<cfoutput>"text_#i#"< /cfoutput> value= "" size="5">
</cfloop>
in the javascript function
//after the connectedIntergroups filled with selected one to add
function connectIntergroups()
{
for(var idx3=1; idx3 < document.frmSearch.Intergr oupID.leng th - 1; idx3++)
{
if (document.frmSearch.text_1 .value == "")
{
document.frmSearch.text_1. value = document.frmSearch.Intergr oupID.opti ons[idx].v alue;
idx3 = document.frmSearch.Intergr oupID.leng th - 1;
}
else if (document.frmSearch.text_2 .value == "")
{
document.frmSearch.text_2. value = document.frmSearch.Intergr oupID.opti ons[idx].v alue;
idx3 = document.frmSearch.Intergr oupID.leng th - 1;
}
//and on it goes to 13
}
}
//similiar for remove
function disconnectIntergroups()
{
for(var idx3=1; idx3 < document.frmSearch.Intergr oupID.leng th - 1; idx3++)
{
if (document.frmSearch.text_1 .value == document.frmSearch.connect edIntergro ups.option s[idx3].se lected)
{
document.frmSearch.text_1. value = "";
idx3 = document.frmSearch.Intergr oupID.leng th - 1;
}
}
}
At the moment I have a very clumsy method of 13 hidden fields - which javascript fills and emptys on the change event. Not finished (or working) - but can you advise - how do you loop an input called text_aVariableNumber in javascript so I don't have all these if statements? Surely there is a better way of coding this. And what happens when you have far more than 13 possibilities?
<!---on the form create 13 text boes (to be hidden)--->
<cfloop index="i" from="1" to="13">
<input type="text" name=<cfoutput>"text_#i#"<
</cfloop>
in the javascript function
//after the connectedIntergroups filled with selected one to add
function connectIntergroups()
{
for(var idx3=1; idx3 < document.frmSearch.Intergr
{
if (document.frmSearch.text_1
{
document.frmSearch.text_1.
idx3 = document.frmSearch.Intergr
}
else if (document.frmSearch.text_2
{
document.frmSearch.text_2.
idx3 = document.frmSearch.Intergr
}
//and on it goes to 13
}
}
//similiar for remove
function disconnectIntergroups()
{
for(var idx3=1; idx3 < document.frmSearch.Intergr
{
if (document.frmSearch.text_1
{
document.frmSearch.text_1.
idx3 = document.frmSearch.Intergr
}
}
}
ASKER
thanks mause - ended up using javascript to ensure the right side was selected (and therefore posted)
Then the loops were a series of converting the querylist into a list value and looping it to insert those not int he select and looping again to delete thos in the list that were not in the select.
thanks
Then the loops were a series of converting the querylist into a list value and looping it to insert those not int he select and looping again to delete thos in the list that were not in the select.
thanks
Looks like u need to use 2 selects box together ...
take a look http://www.geocities.com/thanny/
scroll to bottom right & download CF_TwoSelectsRelated
PS : never use disabled - dosent work in netscape.