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

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)

<script language ="JavaScript" >
function update()
var x=new Array()
var d=new Array();
var cnt=0;
var count=0;
var category=document.catmod.cat_type[selectedIndex].value;
$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) ";
var y='<?=pg_numrows($result4)?>';
<?php for($row=0;$row<pg_numrows($result4);$row++)
if(a=="<?php echo $val['type_no']?>")

<?php } ?>
if(a=="<?php echo $val['type_no']?>")

<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()">

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