TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-25-2008, 01:18 AM   #1 (permalink)
The Wanderer
 
superthin's Avatar
 
Join Date: Aug 2008
Posts: 16
Thanks: 7
superthin is on a distinguished road
Default Could I use Ajax to preload a dropbox?

Hello all,

I have got a html form to input books' information. When I run my PHP script in localhost, everthing is good. The problem is when I upload it to my shared hosting, the hosting provider tells me that my script consumes a lot of server's resources.

My friend told me that I should use Ajax to pre-load dropbox(es). I don't know how to do that.



I want to "Choose a language" (1) it will have an influence on "Choose an author" (2) and "Choose a publisher" (3). That means "When I choose French, American authors and publishers will not to be listed".

I am using an "onchange" event in HTML to refresh / reload. It makes a slow flicker, a long delayed time, a lot of hosting resource,...

Some queries with Google and Altavista I cannot solve the problem. Will everybody here tell me what Ajax tool(s) I should use?

Thanks in advance.

Best regards,
__________________
http://khoancatbetong.com - Vietnamese Concrete Technician Forum
superthin is offline  
Reply With Quote
Old 11-25-2008, 09:13 AM   #2 (permalink)
The Wanderer
Good Samaritan 
 
martins256's Avatar
 
Join Date: Mar 2008
Posts: 18
Thanks: 0
martins256 is on a distinguished road
Default

It's easy with jquery! I'll make an example for you:

some place in your form
HTML Code:
<select name="authors" id="authors" >
<option value="1">French</option>
<option value="2">American</option>
</select>

<select name="publisher" id="publisher" ></select>
JS to do all the ajax magic(I use jquery so you will need that to try my example too).
HTML Code:
$(document).ready(function(){
  $("#authors").change(function(){
    id = $("#authors").val();
    $("#publisher").load("ajax.publisher.php?id="+id);
  });
});

And the "ajax.publisher.php"
PHP Code:
<?php
session_start
();
error_reporting(E_ALL);

include(
'config.php');
include(
'functions.php');

if(isset(
$_GET['id']) and ctype_digit($_GET['id']))
{
  
$sql "SELECT * FROM publishers WHERE author_id = {$_GET['id']}";
  
$result mysql_query($sql);
  while(
$row mysql_fetch_assoc($result))
  {
    echo 
'<option value="'.$row['id'].'">'.$row['publisher'].'</option>';
  }
}
?>
martins256 is offline  
Reply With Quote
The Following User Says Thank You to martins256 For This Useful Post:
superthin (11-25-2008)
Old 11-25-2008, 04:57 PM   #3 (permalink)
The Wanderer
 
superthin's Avatar
 
Join Date: Aug 2008
Posts: 16
Thanks: 7
superthin is on a distinguished road
Default

Oh, thank martins256 very much. I would like to say "You are a star" :)
__________________
http://khoancatbetong.com - Vietnamese Concrete Technician Forum
superthin is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:07 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design