Author Topic: MySQL & Forms  (Read 444 times)

0 Members and 1 Guest are viewing this topic.

Offline mfkamandeTopic starter

  • Irregular
  • Posts: 2
    • View Profile
MySQL & Forms
« on: March 03, 2010, 02:55:57 AM »
I am new to Web development. Am using PHP and My SQL Database. I am developing a transport management system. To manage users for the system, I have a combobox (select) which lists the user codes. I have a text box input which I want to display the name (other details from the database) every time the selection changes. How do I achieve this?

Offline Dennis1986

  • Enthusiast
  • Posts: 78
  • Gender: Male
  • PHP for life!
    • View Profile
    • DennisRasmussen.dk
Re: MySQL & Forms
« Reply #1 on: March 03, 2010, 03:54:59 AM »
If you want this to happen without submitting the form you have to ask in the JavaScript section.
You then have 2 options: Javascript with or without AJAX.

Without AJAX:
Print out the data for the javascript to process with <select onchange="myFunction(this.selectedIndex)">
Code: [Select]
<script type="text/javascript">
var data = new array();
<?php
foreach ($array as $data) {
  echo 
"data[" $data['id'] . "] = $data";
}
?>


myFunction(index) {
  Do stuff with selected index and data here...
}
</script>


With AJAX:
Call for data using AJAX again with <select onchange="myFunction(this.selectedIndex)"> but from an external php file.
« Last Edit: March 03, 2010, 03:55:38 AM by Dennis1986 »
Just ask and I'll answer your question(s)! ;)