Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts

    Stumped passing on variables

    Hope I am posting this in the right forum
    and I hope someone can help me with this.

    I have a page (called page1.php) that has 2 divisions, 1- leftcolumn and 2 - rightcolumn. On this page I have the following code from which the user chooses one of the links.
    These are choices that get passed on to page2.php which takes the users choice and uses it to retrieve data from the database. In other words, get all the data matching series 21, 22 or 23.

    <a href="javascript:ajaxpage('page2.php?series=21', 'rightcolumn');">Series 21</a>
    <a href="javascript:ajaxpage('page2.php?series=22', 'rightcolumn');">Series 22</a>
    <a href="javascript:ajaxpage('page2.php?series=23', 'rightcolumn');">Series 23</a>
    As you can see, the href calls an ajaxpage() function that returns result into a division called 'rightcolumn' on page1.php. The above works just fine because they simply pass on static numbers.

    What I want to do now is pass on 2 variables to page2.php that are user inputs. One is a text input, the other a dropdown variable. The user fills in the text input, chooses a selection from the dropdown and then clicks a submit button (or a URL link or whatever). The idea behind this is that I present the user with a search input which calls the MySQL database routine on page2.php using the 2 variables and presents the results into the rightcolumn division of page1.php.

    I can do this using the following form, but how do I call the ajaxfunction at the same time so that the result will appear in the 'rightcolumn' division?

    <form action="page2.php" method="post">
        Choose Search Type:<br />
        <select name="searchtype">
          <option value="21">Series 21
          <option value="22">Series 22
          <option value="23">Series 23
        <br />
        Enter Search Term:<br />
        <input name="searchterm" type="text" size="40">
        <br />
        <input type="submit" name="submit" value="Search">
    Anybody have any ideas or suggestions on how to accomplish this?
    I've done hours of searching and I am only getting bits and pieces which makes everything even more confusing.

    Last edited by Phoenix649; 02-11-2012 at 01:59 PM. Reason: Forgot something

  2. #2
    Senior Coder Inigoesdr's Avatar
    Join Date
    Mar 2007
    Florida, USA
    Thanked 406 Times in 398 Posts
    Are you still looking to load the page with AJAX? If so you will need to use JavaScript to get the values from the select and text input. If you have jQuery you can do something like this:
    // JavaScript
    function doSearch()
        var series = $('select[name="searchtype"] option:selected').text();
        var term = $('input[name="searchterm"]').val();
        var newURL = 'page2.php?series=' + series + '&term=' + term;
    Not tested, and you don't need to separate the variables if you don't want to. If you want this thread moved to the JavaScript forum let us know and one of the Mods will take care of it.

  3. #3
    New to the CF scene
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts
    Thanks Inigoesdr,
    no jQuery and your suggestion does not seem to call the
    'javascript:ajaxpage('page2.php?series=xxx', 'rightcolumn' function.
    I'm getting the feeling that this may just have to be done through javascript.
    Maybe move this post there?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts