hi ,
* i'am using php & mysql ( with smarty teplate ) .
i have 3 table on my database
Table Governorate
Table Department
Table SupplyOffice
i have a 2 qutions :-
1- i have a page name " add.php " and when i want to insert into database i do this :
1- how to use " OnClick " with
Posted by foobic, 10-21-2012, 09:17 PM
You don't. Instead use onchange and pass the selected option value (this.value) to your handler function.
Posted by scal, 10-21-2012, 09:25 PM
thank you for your reply ,
please can you help me to do this with jquery ?
i want to when i choose the Governorate , that change the Department to be :
thank you
Last edited by scal; 10-21-2012 at 09:29 PM.
Posted by foobic, 10-21-2012, 09:37 PM
http://api.jquery.com/change/
Since that query presumably runs server-side you could either:
preload all options with your javascript and just change to a different set using the jquery handler, orhave your jquery handler use AJAX to fetch the new options from the server.
Which is more practical depends on the amount of data involved.
Posted by scal, 10-21-2012, 10:24 PM
Is there another way to do this but not use Jquery , because i'm just beginner on programming
Posted by Herasil, 10-21-2012, 11:36 PM
Here is a pretty good tutorial on w3schools that shows a way to do it without jQuery: http://www.w3schools.com/php/php_ajax_database.asp
Since you're new the concept, that may be a good starting point. That's also where I started with AJAX. However, I highly recommend that you look into AJAX with jQuery. It's really not that difficult, and is actually simpler than the w3schools method once you get used to jQuery. To help you out, here's a working sample of what you would do using jQuery:
In one .php file:
In another file that may be named get.php:
What's happening is that the AJAX activates each time something with the ID of "governorate" is changed, which in this case is the governorate drop down list. It sends the corresponding ID of the governorate that you clicked on to the get.php file, which reads it into a variable, and then does a query to select all the departments with the matching governorate ID. Then it outputs it in a drop down list of departments, which is then used to replace whatever was in the div with the id of department.
02link provides enterprise hosting and server services at an amazing price. Don't see something that suits your needs? Get a free custom quote from one of our hosting experts.