I know this has been asked previously and I have read all of the post (and more!) on this subject.
Suffice to say that I have a form that actually works now.
What I am trying to do is have two select boxes (dropdown) on my form and the 2nd select box has items in it that are dependent on the 1st select box. So, if I choose an item in the 1st select box the items listed in the 2nd select box are 'related' to the 1st select box. And all of these values are derived from a mySQL DB. The 1st select box obtains records from table A and the 2nd select box obtains records from table B (table A and table B are related by an ID).
The fact is I have this working. The form works great and the select boxes operate as I expect.
The only issue I have is that one of my values from the form is not being saved in the database, and I cannot work out why!?
So here's my form code:
And here's the Javascript that the 1st select box calls:
And then there's the PHP file the JS calls
All OK so far, and as I say the form works a treat.
Here's my INSERT query for the data:
$ur is a SESSION variable I am using for the UserID.
Some of the other table fields are defaulted. Everything saves nicely except for the SubReq.
Now my thinking is that this is empty on the form and I have no real way fo checking it as when I look at the source of the page after the 2nd select box has loaded, it is still blank. So although the 2nd select box is populated after the 1st box is changed, I think the form still thinks there's nothing in it, although that might be silly as there is obviously something in the 2nd select field!
As I say, I'm stumped.
Any ideas/help/advice/suggestions?
Do you need any more info?
Thanks ...
Suffice to say that I have a form that actually works now.
What I am trying to do is have two select boxes (dropdown) on my form and the 2nd select box has items in it that are dependent on the 1st select box. So, if I choose an item in the 1st select box the items listed in the 2nd select box are 'related' to the 1st select box. And all of these values are derived from a mySQL DB. The 1st select box obtains records from table A and the 2nd select box obtains records from table B (table A and table B are related by an ID).
The fact is I have this working. The form works great and the select boxes operate as I expect.
The only issue I have is that one of my values from the form is not being saved in the database, and I cannot work out why!?
So here's my form code:
Code:
<tr>
<td>Request Area</td>
<td>
<select name="request" id="request" onchange="AjaxFunction(this.value);">
<option value=''>Select One</option>
<?php
$q=mysql_query("select * from req_name ORDER BY request");
while($n=mysql_fetch_array($q)){
echo "<option value=$n[id]>$n[request]</option>";
}
?>
</select>
</td>
<td>Sub-request Name</td>
<td>
<div id="subreq">...</div>
</td>
</tr>
<tr>
<td valign="top">Description</td>
<td colspan="3"><textarea cols="50" rows="5" name="description"></textarea></td>
</tr>
And here's the Javascript that the 1st select box calls:
Code:
function AjaxFunction(id) {
var httpxml;
try {
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck() {
if(httpxml.readyState==4) {
document.getElementById("subreq").innerHTML=httpxml.responseText;
}
}
var url="req.php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
And then there's the PHP file the JS calls
Code:
<?
$id=$_GET['id'];
include '/home/piglcouk/public_html/includes/dbc.php';
$q=mysql_query("select * from sub_reqs_name where req_id='$id'");
echo mysql_error();
echo "<select name='SubReq'>";
while($nt=mysql_fetch_array($q)) {
echo "<option value='$nt[id]'>$nt[sub_req]</option>";
}
echo "</select>";
?>
All OK so far, and as I say the form works a treat.
Here's my INSERT query for the data:
Code:
INSERT INTO requests (user_id,date,description,request,sub_req) VALUES ($ur,NOW(),'$_POST[description]','$_POST[request]','$_POST[SubReq]')
Some of the other table fields are defaulted. Everything saves nicely except for the SubReq.
Now my thinking is that this is empty on the form and I have no real way fo checking it as when I look at the source of the page after the 2nd select box has loaded, it is still blank. So although the 2nd select box is populated after the 1st box is changed, I think the form still thinks there's nothing in it, although that might be silly as there is obviously something in the 2nd select field!
As I say, I'm stumped.
Any ideas/help/advice/suggestions?
Do you need any more info?
Thanks ...