Highlighted

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

New Here ,
Jun 16, 2019

Copy link to clipboard

Copied

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>

Views

560

Likes

Translate

Translate

Report

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

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

New Here ,
Jun 16, 2019

Copy link to clipboard

Copied

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>

Views

561

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 16, 2019 0
LEGEND ,
Jun 17, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi WolfShade,

Thank you for the reply!

Could you please given a example of the code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 0
LEGEND ,
Jun 18, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2019 0
LEGEND ,
Jun 20, 2019

Copy link to clipboard

Copied

Hello,

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

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 20, 2019 0
BKBK LATEST
Adobe Community Professional ,
Jun 20, 2019

Copy link to clipboard

Copied

<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#" >

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 20, 2019 0