Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2012, 12:58 PM   PM User | #1
Phoenix649
New to the CF scene

 
Join Date: Feb 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Phoenix649 is an unknown quantity at this point
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

Last edited by Phoenix649; 02-11-2012 at 12:59 PM.. Reason: Forgot something
Phoenix649 is offline   Reply With Quote
Old 02-11-2012, 02:30 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 02-12-2012, 11:57 AM   PM User | #3
Phoenix649
New to the CF scene

 
Join Date: Feb 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Phoenix649 is an unknown quantity at this point
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?
Phoenix649 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:09 PM.


Advertisement
Log in to turn off these ads.