[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple thing is KILLING me

Posted on 2005-04-26
11
Medium Priority
?
254 Views
Last Modified: 2013-12-24
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
Comment
Question by:benpung
  • 5
  • 5
11 Comments
 
LVL 9

Expert Comment

by:CFDevHead
ID: 13869130
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
 
LVL 1

Author Comment

by:benpung
ID: 13869317
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
 
LVL 1

Author Comment

by:benpung
ID: 13869323
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
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
LVL 9

Accepted Solution

by:
CFDevHead earned 500 total points
ID: 13869370
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
 
LVL 1

Author Comment

by:benpung
ID: 13869390
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
 
LVL 9

Expert Comment

by:CFDevHead
ID: 13869419
yes it is. it would require  a lot more JS
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 13869420
If I was you I would post a question over in the JS section of EE
0
 

Expert Comment

by:benlinton
ID: 13877919
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
 
LVL 1

Author Comment

by:benpung
ID: 13881052
I'll play with this and let you know.  thanks.
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 13973646
Are you still working on this?
0
 
LVL 1

Author Comment

by:benpung
ID: 13976620
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
What You Need to Know when Searching for a Webhost Provider
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question