Skip to main content
Inspiring
February 19, 2014
Answered

<cfif IsDefined("form.MySelect")

  • February 19, 2014
  • 1 reply
  • 3416 views

I want to to pass the value users select from form.MySelect.

I use

<cfif IsDefined("form.MySelect")

</cfif>

it seems that ColdFusion server does not recognize it.

It works if I use text control.

I would like to know are there anyway to pass select value to ColdFsuion server to use <CFIF IsDefined>

If not, any suggestions or use hidden controls to set the value when user select a value from drop down box.

Your help and information is great appreciated,

Regards,

Iccsi,

    This topic has been closed for replies.
    Correct answer BKBK

    here is html code:

    <input name="cmdSubmit" type="submit" id="ccdSubmit" value="CONFIRMAR"/>

    here are my on submit code ,

    I still do not see the select even I comment event.preventDefault,

    jQuery("#cmdSubmit").click(function(event) {

              

     

      

      <!---  event.preventDefault();--->

       

       if (validate())

       {

      

        if (document.MyForm.MyNumber.value.length == 0)

         {

       document.MyForm.MyNumber.value =

          document.getElementById('MyForm').hidNumber.value;

         }

       

      

      

        jQuery.ajax({

         url:  "/Mycfm.cfc?method=MyMethod&MyNumber="   ("#txtMyNumber").val()),

      

      

         type: "POST",

         success: function(data)

         {

        

          alert( "My Number " + GetMyNumber(jQuery("#txtMyNumber").val()) +

          " for " + GetMyNumber(jQuery("#MyName").val()) +

           " Data update completed");

        

         

         }

        });

       }

       

      });


      <!---  event.preventDefault();--->

    Shouldn't that be /* event.preventDefault(); */ ? Anyway, from what I have read about event.preventDefault(), its purpose is to prevent the default click-action which, in this case, is form submission. So it is actually doing what it is designed to do! Why don't you comment it out?

    1 reply

    BKBK
    Community Expert
    Community Expert
    February 19, 2014

    Coldfusion does recognize it. Use the value of the name attribute of the select field. For example,

    <cfif isDefined("form.mySelect")>

    form.mySelect: <cfoutput>#form.mySelect#</cfoutput>

    </cfif>

    <cfform action="#cgi.SCRIPT_NAME#">

    <cfselect name="mySelect">

    <option value="1">Yes</option>

    <option value="0">No</option>

    </cfselect>

    <cfinput name="sbmt" type="submit" value="send">

    </cfform>

    iccsiAuthor
    Inspiring
    February 19, 2014

    I use cfselect like following code,

    "hello" shows when I use <cfif not isDefined>, it does not show isDefined,

    Thanks again,

    Regards,

    <cfif isDefined("form.lstMylst")>

        hello

    </cfif>

    <td>
      <cfselect name="lstMylst" id="lstMylst">

             <cfoutput query="myQuery">
             <option value="#MyQuery.MyID#"
                <cfif (isDefined("form.MyID") AND form.MyID EQ myQuery.MyID)>selected="selected"</cfif>> #MyQuery.MyName# </option>
                
             </cfoutput>

      </cfselect>

    </td>

    BKBK
    Community Expert
    Community Expert
    February 19, 2014

    The form is probably not submitted, is submitted to a different action page or has method type 'get'. To test, temporarily replace

    <cfif isDefined("form.lstMylst")>

        hello

    </cfif>

    with 

    <cfif isDefined("url.lstMylst")>

        hello

    </cfif>

    <cfdump var="#url#" label="URL scope">

    <cfdump var="#form#" label="Form scope">

    Do you see 'hello'? Are the URL or form variables dumped?