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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

set a session variable

I have the form where I want to assign an id as a step selected. from the drop down I select the course of action . All entry from drop down should have an id of which determine th enext step  and based upon selection I need to enable session variables for example if the business is selected it will generate the id 2 and set the session variable = session.business and so on
function validateForm(objForm){
      var strErr='';
     
      if(!objForm.school.options[objForm.school.selectedIndex].value){
            strErr='Invalid Selection!\nUnable to submit form.\nPlease make a valid selection and try again.'
      }
     
      if(strErr){
            alert(strErr);
      }else{
          objForm.action='?debug&step='+objForm.school.options[objForm.school.selectedIndex].value;
      }

return !strErr;

}

function setSession (obj){

      if (obj.value=='business'){
            <cfoutput><cfset session.schoolcode='business'>
            <cfset step=2></cfoutput>
      
      }

if (obj.value=='education'){
            <cfoutput><cfset session.schoolcode='education'><cfset step=2></cfoutput>
      
      }

if (obj.value=='psl'){
            <cfoutput><cfset session.schoolcode='psl'><cfset step=2></cfoutput>
      
      }
      
}




</script>
</cfoutput>
    <cfparam name="form.school" default="">
    <div id="menuOption">
    <h2 style="margin:20px;">Please select a desired school:</h2>
  <form action="" method="post" enctype="multipart/form-data" onSubmit="return validateForm(this)" onclick="setSession (this);">
             <select name="school" id="school">
<!---<option>Please select a school</option>
<option value="2">Business</option>
<option value="2">Education</option>
<option value="2">PSL</option>--->
<option>[Please select a school]</option>
<cfoutput query="school">
<option value="#school_division#">#school_division#</option>
</cfoutput>
                 
               
        </select>
               
                <input type="submit" value="Select School" id="btnsubmit" >
      </form>
      </div>
 
0
erikTsomik
Asked:
erikTsomik
  • 2
  • 2
1 Solution
 
Russell2566Commented:
I'm confused by the ColdFusion code wrapped in JS Logic code? The JS logic will not fire off this coldfusion code it will ALL be run at render time...

Also, you don't need to wrap all your code in cfoutputs...

You will want to modify form inputs and submit the form to the next page using 100% JS... If you still need something set into the session scope, that is where you will do it (on page 2).
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
I want to set the session variable once i clik on submit
0
 
Russell2566Commented:
You won't be able to do that on that page...

You will have to do it on the page you submit to...

<cfset session.schoolcode = form.schoolcode>
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
That works. All i had to do is to put it in the different function. By the chance do you know how to work with the tabbed panels in Spry
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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