3 Replies Latest reply on Jun 10, 2008 10:42 AM by John Spillman

    converting javascript variable to coldfusion

    torstenp Level 1
      I am running a form that submits data via the cf ajax to a .cfc file --
      when it returns to the calling page -- i turn the forms into text and remove the form fields.
      the problem is i run the statement:
      document.getElementById("PROGRAM_TYP").innerHTML = document.myform.PROGRAM_TYP.value;

      most of the items submitted are just text values and the value of the form field is the actual display text which then populates correctly.
      in this case -- the form field is a select where and ID is used -- so when i go to populate the <td> with the submitted value -- it only puts in the ID (as this was the actual submitted value)

      i am trying to take this submitted value and resolve the ID back to the display value and use this value in place of the document.myform.PROGRAM_TYP.value

      what i need to be able to do is convert the document.myform.PROGRAM_TYP.value into something i can plug into CFQUERY.
      or use the <cfreturn> to return and catch a specific variable.
        • 1. Re: converting javascript variable to coldfusion
          samunplugged Level 1
          It seems you need to change the value of id attribute of <option> tags.

          Can you try removing the id attribute from select? Or use such values for id attribute that can be used in the action page

          • 2. Re: converting javascript variable to coldfusion
            torstenp Level 1
            i think i used the wrong wording in my original question.
            the ID i was referring to was the database ID value
            like query of:
            ID NAME
            1 Red
            2 Blue
            3 Green

            in my select statement -- the ID is the value that is submitted by the form and held in the database. (not the ID of an html tag).
            so when the form is submitted - i have the value but not the database resolved value of that field.
            for instance the form value was 2, the code places 2 into the corresponding database field. but i want to now display the value of 2 in clear text as 'Blue' -- i am trying to do this via a query that was run and have the result passed from the cfc to the webpage to populate the innerHTML value
            • 3. Re: converting javascript variable to coldfusion
              John Spillman
              How about using another Hidden input field that is bound to the value you select and looks up its value as you select 1, 2, or 3.

              <cfselect name="select_color">
              <option value="1 Red">1 Red</option>
              <cfinput type="hidden" name="hidden_color" bind="cfc:cfc_filename.method_name({select_color})" />

              Your method in your CFC would have to return the query value of Red if select_color was selected as 1 Red, then you could use the document.formName.hidden_color.value in your javascript.