coldfusion button type="button"

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();" >
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
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
WaldenLCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erikTsomikSystem Architect, CF programmer Author Commented:
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
WaldenLCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

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.