...

View Full Version : Make the options of preceding fields dependent on the previous options selected dyn.



imqhsproj
01-11-2006, 05:24 AM
Hello friends,
I'm having a problem in trying to update the PRECEDING entries of the (SELECT OPTION)fields OF A FORM depending on the previous choice of the user on the same page (without refreshing the page).

I'm having a setup of Postgresql 7.1 as the database PHP 4 is the front end and apche server 4.

I tried using a combination of javascript and php but couldnt get it right .There is some sort of a syntactic error or something or the way im supossed to embed javascript within php and vice versa.The following is what I have tried.

Here category is one of the fields and the rest of the select fields are supposed to be generated dynamically depending on the input of category (every select field depends on the previous one)

<html>
<head>
<script language ="JavaScript" >
function update()
{
a=document.catmod.cat_type.value;
var x=new Array()
var d=new Array();
var cnt=0;
var count=0;
var category=document.catmod.cat_type[selectedIndex].value;
<?php
$db_handle =include("dbconnect.php");
$q4="select A.type_no,A.type_name,B.mod_no, B.mod_name from category as A, module as B, contains as C where (A.type_no=C.type_no) and (B.mod_no=C.mod_no) ";
$result4=pg_exec($db_handle,$q4);
echo"pg_numrows($result4)";
?>
var y='<?=pg_numrows($result4)?>';
alert("y");
//echo"<select>";
<?php for($row=0;$row<pg_numrows($result4);$row++)
{
$val=pg_fetch_array($result4,$row);
$val1=pg_result($result4,$row,'mod_name');
?>
alert("gfd");
if(a=="<?php echo $val['type_no']?>")

x='<?=$val1?>';
<?php } ?>
document.catmod.mod_type.text=x;
alert(document.catmod.mod_type.text);
document.write(x);
if(a=="<?php echo $val['type_no']?>")
<?php
echo"$val1";
echo"<option>$val['mod_name']</option>";
}?>
}

</script>
</head>
<body>
<form method="POST" name="catmod" >
<p><font face="MS Serif" size="5">CATEGORY</font><font size="6" face="MS Serif">&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<select name="cat_type" OnChange="update()">
</select>

firepages
01-11-2006, 08:11 AM
All of the PHP code in your javascript function has run before the browser receives the page, it simply does not work like that, if you want to do this without a page refresh you need to look into AJAX or similar XMLHttpRequest based technologies



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum