• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Simple thing is KILLING me

I think this should be pretty simple, but i'm having a hard time with it.  I have two dropdown boxes.  the first box is populated from a cfquery to the database as follows.  after a value us selected, the form submits itself to itself, the page is reloaded, and i have a second box that is populated based on the first (also below).  that works fine.  my problem is that i also have a submit button on the bottom of the form.  when the first dropdown box is selected, i want the form to submit to itself so the second dropdown is populated.  when the submit button is clicked, i want the form submitted to SomePace.cfm.  Is there a way to do this?

<!-- form -->
<form method="post" name="IncidentForm" action="SomePage.cfm">
<!-- first box -->
<select name="IncidentNumber" onchange="this.form.submit()">
<cfoutput>
<option>Select Incident Number</option>
<cfloop query="GetIncidentNumber">
         <option value="#GetIncidentNumber.INCIDENT_NUMBER#" <cfif isDefined('form.IncidentNumber')><cfif form.IncidentNumber eq "#GetIncidentNumber.INCIDENT_NUMBER#">selected</cfif></cfif>>#GetIncidentNumber.INCIDENT_NUMBER#</option>
     </cfloop>
</select>

<! -- second box popluated on based on value of first box -->
<cfif isDefined('page.IncidentNumber')>
<cfquery dbtype="query" name="GetSiteName">
SELECT SITE_NAME
FROM GetIncidentfields
WHERE INCIDENT_NUMBER = #page.IncidentNumber#
ORDER BY SITE_NAME ASC
</cfquery>

  <!--- second drop down list --->
   <select name="SiteName">
      <cfloop query="GetSiteName">
         <option value="#SITE_NAME#">#SITE_NAME#</option>
      </cfloop>
   </select>
</cfif>
</cfoutput>
<input type="button" name="SubmitForm" value="Submit">
<input type="reset" name="ResetForm" value="Reset">
</form>
</body>
</html>
0
benpung
Asked:
benpung
  • 5
  • 5
1 Solution
 
CFDevHeadCommented:
you can do this using javascript
like this
<script>
function postSomewhere(){
      frm=document.IncidentForm
      frm.action=SomePage.cfm'
      frm.method='post'
      frm.submit()
}
</script>
<!-- form -->
<form method="post" name="IncidentForm" action="SomePage.cfm">
<!-- first box -->
<select name="IncidentNumber" onchange="this.form.submit()">
<cfoutput>
<option>Select Incident Number</option>
<cfloop query="GetIncidentNumber">
         <option value="#GetIncidentNumber.INCIDENT_NUMBER#" <cfif isDefined('form.IncidentNumber')><cfif form.IncidentNumber eq "#GetIncidentNumber.INCIDENT_NUMBER#">selected</cfif></cfif>>#GetIncidentNumber.INCIDENT_NUMBER#</option>
     </cfloop>
</select>

<! -- second box popluated on based on value of first box -->
<cfif isDefined('page.IncidentNumber')>
<cfquery dbtype="query" name="GetSiteName">
SELECT SITE_NAME
FROM GetIncidentfields
WHERE INCIDENT_NUMBER = #page.IncidentNumber#
ORDER BY SITE_NAME ASC
</cfquery>

  <!--- second drop down list --->
   <select name="SiteName">
      <cfloop query="GetSiteName">
         <option value="#SITE_NAME#">#SITE_NAME#</option>
      </cfloop>
   </select>
</cfif>
</cfoutput>
<input type="button" onClick="postSomewhere()"  name="SubmitForm" value="Submit">
<input type="reset" name="ResetForm" value="Reset">
</form>
</body>
</html>
0
 
benpungAuthor Commented:
unless i'm missing something (and it's possible as i'm a CF rookie), this will not do what i want.  when i use this, the page submits itself to SomePage.cfm when i change the value in the first dropdown box.  If i have an action in the <form> tag

<form method="post" name="IncidentForm" action="SomePage.cfm">

and then this line to submit the form onchange,

<select name="IncidentNumber" onchange="this.form.submit()">

it is submitting the form to SomePage.cfm when i change value in the first box.  i only want the page to submit to itself when the first box changes, then submit to SomePage.cfm when i click the "submit" button.

am i missing something in your example?
0
 
benpungAuthor Commented:
is there a way to just put the loading of the second dropdown in a function or something?  i'm open to other methods other than what i have here.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
CFDevHeadCommented:
this JS will do that for you
<script>
function postSomewhere(){
     frm=document.IncidentForm
     frm.action='SomePage.cfm' <------Insert the page that you want it to post to
     frm.method='post'
     frm.submit()
}
</script>
0
 
benpungAuthor Commented:
i think i might have figured it out.  let me know if this is correct:

i took the action out of the <form> tag so it looks like this:

<form method="post" name="IncidentForm">

we were missing a single quote in this line:

frm.action=SomePage.cfm'

i think it's working now.

i am still curious if it's possible to put the loading of the second dropdown into it's own javascript function using CF and javascript.
0
 
CFDevHeadCommented:
yes it is. it would require  a lot more JS
0
 
CFDevHeadCommented:
If I was you I would post a question over in the JS section of EE
0
 
benlintonCommented:
Hang on, don't faff with javascript!

Pass a few extra variables with your forms and switch on them.  For instance, on first submission, send a variable "form.first_submit" to the form.  In the form include code such as:

<cfif isdefined("form.first_submit")></cfif>

and put your second drop down box inside the cfif.  

Back in the form, change the action of the form dependant on the presence of the "form.first_submit" variable.  If it is defined, then you know it is the second submit of the form and that you want the from action to be something different, so:

<form method="post" name="IncidentForm" action="SomePage.cfm">

becomes

<form method="post" name="IncidentForm" action="<cfif isdefined("form.first_submit")>somepace.cfm<cfelse>SomePage.cfm</cfif>">
0
 
benpungAuthor Commented:
I'll play with this and let you know.  thanks.
0
 
CFDevHeadCommented:
Are you still working on this?
0
 
benpungAuthor Commented:
sorry for the delay in accepting the answer.  i've been working on something else the last few days and have gotten away from this.  thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now