Filter from $_GET

Filter from $_GET

MathiasLMMathiasLM Posts: 5Questions: 0Answers: 0
edited March 2010 in General
Hey, I'm working on a site with a typical datatable on a secondary site.

I would like for my users to be able to type in a string on the frontpage, press enter, and then be directed to my datatable-site, where the string they typed will then be the filter for the datatable.

I'm no javascript-shark, so this might be a silly question :)

Replies

  • MathiasLMMathiasLM Posts: 5Questions: 0Answers: 0
    Bump
  • achlanachlan Posts: 20Questions: 0Answers: 0
    Hi,
    maybe something like this can help:
    [code]
    $(document).ready(function() {
    $('#example').dataTable({
    "fnInitComplete": function() {
    $(".top input:first").text("<? echo $_GET['your_string']?>").focus();
    }
    });
    });
    [/code]
    Regards
    achlan
  • MathiasLMMathiasLM Posts: 5Questions: 0Answers: 0
    That helped a lot actually!

    Here I'm just trying the idea out with some random value:

    [code]
    $(document).ready(function() {
    $('#example').dataTable({
    "fnInitComplete": function() {
    $("input:first").text("test").focus();
    }
    });
    });
    [/code]

    That puts the field in focus, but leaves the value empty.
    I'm pretty sure this is just a pretty basic javascript mistake, but as I said, I'm not too familiar with it :)

    Any suggestions?
  • MathiasLMMathiasLM Posts: 5Questions: 0Answers: 0
    Through google, I figured out to replace
    [code]text("test")[/code]
    with
    [code]val("test")[/code]
    Which leads me to my next question:

    How do I make it run the search?
    (as it is now, it just has the default value "test", but lacks the user-input "enter")
  • achlanachlan Posts: 20Questions: 0Answers: 0
    edited April 2010
    ok, also fire an keyup event. the focus isn´t necessary:
    [code]
    $(document).ready(function() {
    $('#example').dataTable({
    "fnInitComplete": function() {
    $("input:first").val("test").keyup().focus();
    }
    });
    });
    [/code]
  • MathiasLMMathiasLM Posts: 5Questions: 0Answers: 0
    Awesome!

    I finally got it to work perfectly from a post input field.

    Thank you SO much for helping me out Achlan! :D
This discussion has been closed.