CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   Stumped passing on variables (http://www.codingforums.com/showthread.php?t=251312)

Phoenix649 02-11-2012 12:58 PM

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.

Code:

<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?

Code:

<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
    </select>
    <br />
    Enter Search Term:<br />
    <input name="searchterm" type="text" size="40">
    <br />
    <input type="submit" name="submit" value="Search">
  </form>

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.

Thanks

Inigoesdr 02-11-2012 02:30 PM

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:
Code:

// 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;
    ajaxPage(newURL);
}

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.

Phoenix649 02-12-2012 11:57 AM

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?


All times are GMT +1. The time now is 07:15 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.