Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get jquery value in coldfusion variable OR how to get input text value in cold fusion variable

New Here ,
Jun 16, 2019 Jun 16, 2019

Please help me to get the $("#txt").val(id); ​into coldfusion variable to do some sql query. Thanks

<body>

<script>

$(document).ready(function (){

$(".ap").click(function (){

var id = this.id;

$("#txt").val(id);

})

})

</script>

<div id="Test" class="ap">click</div>

<input id="txt" name="txt" value="" type="text">

</body>

2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2019 Jun 17, 2019

If you're asking how to put a jQuery value into a CF variable, the only way I've done it is to use AJAX to submit the value to a .cfm page and set a session variable.

But there might be other ways to do it.  This is the way I do it.

HTH,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2019 Jun 17, 2019

Hi WolfShade,

Thank you for the reply!

Could you please given a example of the code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 18, 2019 Jun 18, 2019

I can try.  Very basic, bare-bones example.  This assumes you are using jQuery 1.x.

setSV.cfm:

<cfswitch expression="#StructKeyExists(form,"yourVariable")#"> 

     <cfcase value="true"> 

          <cfset session.yourVariable = form.yourVariable />Success! 

     </cfcase> 

     <cfdefaultcase> 

          Failed. 

     </cfdefaultcase> 

</cfswitch>

index.cfm:

<form id="yourForm" name="yourForm">

   <input id="yourVariable" name="yourVariable" />  <button id="sendIt" type="button">Set Your Variable in CF</button>

</form>

<script src="jquery-1.11.2.min.js"></script>

<script>

    $('#sendIt').on('click',function(){

        switch($('#yourVariable').val().trim()){

            case "":

                alert("There must be a value to do this.")

            break;

            default:

                $.post(

                    "setSV.cfm",

                    {yourVariable: $('#yourVariable').val().trim()}

                    ).done(function(data){alert(data);});

            break;

               }

        });

   

</script>

I have not tested the CF on this, but the form/jQuery is working.

HTH,

^ _ ^

UPDATE:  Finally tested it on a local server.  There are some typos, I am correcting them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 20, 2019 Jun 20, 2019

Hello,

Just following up to see if any of this was helpful.

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2019 Jun 20, 2019
LATEST

<script type="text/javascript">

$(document).ready(function (){

    $(".ap").click(function (){

        var id = this.id;

        $("#txt").val(id);

       $("#myFormId").submit()

    })

})

</script>

<body>

    <div id="Test" class="ap">click</div>

   <form id="myFormId" method="post">

    <input id="txt" name="txt" value="" type="text">

    </form>

</body>

<!--- Test it --->

<cfdump var="#form#" >

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources