I have a form that starts with choosing a category and a subcategory. The categories and subcategories are read from a mysql database using a PHP script. When New is chosen from Category I want the Category chose to change from a select to a text input box for both the Category and Subcategory fields. When new is chosen in subcategory and want the form field for subcategory alone to change to a text input box.

I can get the subcategory boxed changed. I can't get the javascript to have the PHP change both the category and subcategory at the same time. It appears to only allow me to change the contents of one <td> area on the form not two. (Yes I know we shouldn't be using td for this but it is a legacy FP site I just took over. Just figuring out how to use PHP with FP was fun)
Essentially the relevent html code is this

form action="process.php" method="post">
                                              <table>
<? if ($ERRORS=="Y") echo "<tr><td>There are errors on the page.</td><td>All errors marked in red.</td></tr><tr><td></td></tr>";?> <tr><td>Required fields marked with *</td></tr> <tr>
                                                  <td>Category*:</td>
<td><div id="cat"><select name="category" onchange="showSubcategory(this.value)"> <option VALUE = "selected"> SELECT</option> <option value="NEW">NEW</option> <?$myrow = mysql_fetch_array($result); echo "<option value=" .$myrow['category']; echo ">". $myrow['category']. "</option>"; if ($myrow = mysql_fetch_array($result)) {
                                                // display list
                                                do {
echo "<option value=" .$myrow['category']. ">". $myrow['category']. "</option>"; } while ($myrow = mysql_fetch_array($result));
                                               } else {
                                           // no records to display
echo "Sorry, no records were found!"; } ?> </select> </div></td> </tr> <tr>
                                                  <td>Subcategory*:</td>
                                                  <td><div id="txtHint">
<select name='subcategory' onchange="showSubcategory2(this.value)"> <option VALUE = "selected"> SELECT</option> <option VALUE="NEW">NEW</option>
                                                 </select>
                                                 </div></td>
                                              </tr>


The java script is here




var xmlHttp

function showSubcategory(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getsubcategory.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
 {
 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 }
catch (e)
 {
 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
}
return xmlHttp;
}

I'm sure this is real easy but javascript is my new toy. I promise to try and be helpful to people on PHP problems.

--
Michael Horowitz
Your Computer Consultant
http://yourcomputerconsultant.com
561-394-9079



*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************

Reply via email to