0

Is it possible to pass a variable from one page to the next page and running that variable at the same time?

What I am trying to do is have a search bar that allows the user to search and upon enter opening up a new page that has a datatable. I want to pass what they type into search bar into the search bar of the datatable and have the results shown.

<!-- START Search form-->
            <form role="search" action="searchalltransactions.cfm" class="navbar-form">
               <div class="form-group has-feedback">
                  <input type="text" placeholder="Type and hit enter ..." class="form-control">
                  <div data-search-dismiss="" class="fa fa-times form-control-feedback"></div>
               </div>
               <button type="submit" class="hidden btn btn-default">Submit</button>
            </form>
            <!-- END Search form-->

Is something like this possible? I am not familiar with this and just trying to learn how to do this if its even possible.

How can I pass this into the (search that datatables creates) on the next page searchalltransactions.cfm

Search that jquery datatables creates

 <input class="form-control input-sm" placeholder="" aria-controls="processing1" type="search">
David Brierton
  • 6,977
  • 12
  • 47
  • 104

3 Answers3

1

While I am not familiar with datatables, or much of what you are doing, I do think I can help. You can use localStorage with javascript to store the variable.

localStorage.setItem("userSearch", value);

In this code "userSearch will be the name of the variable, and value is the value of the search. this will be stored similar to cookies, only that localStorage doesn't have an expiration date.

Then when you want to use the value you would run

var search = localStorage.search;

You will need to compensate for any data type other than string by parsing localStorage.search

I hope that this at least leads you in the right direction, and that if this is not a feasible solution, I hope you find one.

Lordbug
  • 119
  • 1
  • 10
1

From the comments - i can pass it through the url and have it say searchalltransactions.cfm?search=33 but how can i get the 33 to show in the jquery datatables search

Change this:

<input class="form-control input-sm" 
placeholder="" aria-controls="processing1" type="search">

to this:

<cfoutput>
<input class="form-control input-sm" 
placeholder="" aria-controls="processing1" type="search"
value="#url.search#">
</cfoutput>
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
  • the problem with that is its not hardcoded with me. Jquery datatables creates that input and its not actually a search menu created from me :( – David Brierton Mar 31 '17 at 22:40
1

It's a little goofy, but you can do this on the results page, after datatables is initialized:

<cfoutput>
<script>
table.search( '#url.search#' ).draw();
</script>
</cfoutput>

Keep in mind this is running in javascript. All database results are being loaded into the browser, which is then filtering. If you're going to GET or POST a search, you should do your filtering/searching in the database query instead.

More on this: https://datatables.net/reference/api/search()

Jules
  • 1,941
  • 15
  • 18