Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

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();" >
Avatar of Ashish Patel
Ashish Patel
Flag of India image

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();" >
ASKER CERTIFIED SOLUTION
Avatar of WaldenL
WaldenL

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of erikTsomik

ASKER

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
Avatar of WaldenL
WaldenL

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