Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

coldfusion button type="button"

Posted on 2007-10-03
4
Medium Priority
?
1,599 Views
Last Modified: 2013-12-20
I have coldfusion form where I need to update the selected option. So everything is qworking except that is does not update the dataabse
My JS is here
function saveSel (){


      if (document.all) {
      document.getElementById('requirements').options[document.getElementById('requirements').selectedIndex].text = document.getElementById('EditDIV').value;
     // document.getElementById('EditDIV').value='';
        document.getElementById('EditDIV').style.display='none';
 document.getElementById('mainEditor').style.display='none';
     
       
} else {
        document.getElementById('requirements').options[document.getElementById('requirements').selectedIndex].text = document.getElementById('EditDIV').value;
  //    document.getElementById('EditDIV').value='';
      document.getElementById('EditDIV').style.display='none';
        document.getElementById('mainEditor').style.display='none';
     
        }
            <cfif (isDefined("form.EditDIV") and isDefined("form.prereq2") and isDefined("form.hidden"))>
     <cfdump var="#form#">
   

     <cfparam name="form.EditDIV" default="">
        <cfparam name="form.prereq2" default="">
        <cfparam name="form.hidden" default="">
        <cfparam name="requirements" default="">
         
       
        <cfquery name="updateRequirements" datasource="HotBanana_Manager">
                              Update trnAcademicProgramRequirements
                                     set requirement= '#HTMLEditFormat(form.EditDIV)#', req_prereq='#HTMLEditFormat(form.prereq2)#' , hidden='#HTMLEditFormat(form.hidden)#'
                                          where reqid = #form.requirements#      
                        
                        </cfquery>
       
                </cfif>
}
And the button is here
<input type="button" name="save" id="save" value="Save" onclick="saveSel();" >
0
Comment
Question by:erikTsomik
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20006167
Use this
function saveSel (){


      if (document.all) {
      document.getElementById('requirements').options[document.getElementById('requirements').selectedIndex].text = document.getElementById('EditDIV').value;
     // document.getElementById('EditDIV').value='';
        document.getElementById('EditDIV').style.display='none';
 document.getElementById('mainEditor').style.display='none';
     
       
} else {
        document.getElementById('requirements').options[document.getElementById('requirements').selectedIndex].text = document.getElementById('EditDIV').value;
  //    document.getElementById('EditDIV').value='';
      document.getElementById('EditDIV').style.display='none';
        document.getElementById('mainEditor').style.display='none';
     
        }
document.forms[0].submit();
}
            <cfif (isDefined("form.EditDIV") and isDefined("form.prereq2") and isDefined("form.hidden"))>
     <cfdump var="#form#">
   

     <cfparam name="form.EditDIV" default="">
        <cfparam name="form.prereq2" default="">
        <cfparam name="form.hidden" default="">
        <cfparam name="requirements" default="">
         
       
        <cfquery name="updateRequirements" datasource="HotBanana_Manager">
                              Update trnAcademicProgramRequirements
                                     set requirement= '#HTMLEditFormat(form.EditDIV)#', req_prereq='#HTMLEditFormat(form.prereq2)#' , hidden='#HTMLEditFormat(form.hidden)#'
                                          where reqid = #form.requirements#  
                        </cfquery>
                </cfif>
<input type="button" name="save" id="save" value="Save" onclick="saveSel();" >
0
 
LVL 3

Accepted Solution

by:
WaldenL earned 2000 total points
ID: 20006201
erikTsomik,

By the looks of it, the coldfusion code will never run. Your button is not a submit button, just a plain-old-button with a click event. The click event runs on the browser and performs your javascript. However, no where in your JS do you ever submit the form, so the browser doesn't know that it's suposed to post the data back to the web server. Since the data is never posted back to the web server the coldfusion code never runs... hence, the update never occurs.

You either want to make that button a submit button, or you want to do a form.submit in your javascript.

-Walden
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 20006245
OK. It does the same effect as was using submit button. What I need is to be able update the content and once the button is clicked see the changes without refreshing the page
0
 
LVL 3

Expert Comment

by:WaldenL
ID: 20006513
What do you mean "without refreshing the page"? When you do a submit you're back on the server, just load the page with the new data before you redisplay it.

Or are you looking to do more of an Ajax update thing? In that case you'll need two CFM pages, one to load the page, and one to process the update. And then you'll need to use XMLHttpRequest to "call" the update page. If you're looking at Ajax I'd strongly recommend looking at the prototype.js (www.prototypejs.org) framework. I'm not associaed with it at all, other than a happy user!

-Walden
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
What You Need to Know when Searching for a Webhost Provider
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…

564 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