Jump to content

How to get a value from a different file ??


vanvoquan

Recommended Posts

I have this form call test.html

<!doctype html public "-//w3c//dtd html 3.2//en"> 
<html> 
<head> 
<title>(Type a title for your page here)</title> 
<script language="javascript" src="list.php"></script> 
</head> 

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();"> 

<FORM name="drop_list" action="index.php" method="POST" > 
         
<SELECT  NAME="Category" onChange="SelectSubCat();" > 
<Option value="">Category</option> 
</SELECT>  
<SELECT id="SubCat" NAME="SubCat"> 
<Option value="">SubCat</option> 
</SELECT> 
</form> 

</body> 

</html>  

 

And this file to handle the queries of the form, call getit.php

<?php 
require "config.php"; // database connection details  
echo " 

function fillCategory(){  
// this function is used to fill the category list on load 

"; 

$q1=mysql_query("SELECT categories.categories_id, categories_description.categories_name FROM categories_description, categories WHERE  categories_description.categories_id = categories.categories_id AND categories.parent_id = '0'"); 
echo mysql_error(); 
while($nt1=mysql_fetch_array($q1)){ 
echo "addOption(document.drop_list.Category, '$nt1[categories_id]', '$nt1[categories_name]');"; 
}// end of while 
?> 
} // end of JS function 

function SelectSubCat(){ 
// ON or after selection of category this function will work 

removeAllOptions(document.drop_list.SubCat); 
addOption(document.drop_list.SubCat, "", "SubCat", ""); 

// Collect all element of subcategory for various cat_id  

<? 
// let us collect all cat_id and then collect all subcategory for each cat_id 
$q2=mysql_query("select distinct(categories_id)  from categories where parent_id='0'"); 
// In the above query you can collect cat_id from category table also.  
while($nt2=mysql_fetch_array($q2)){ 
//echo "$nt2[categories_id]"; 
echo "if(document.drop_list.Category.value == '$nt2[categories_id]'){"; 
$q3=mysql_query("SELECT categories.categories_id, categories_description.categories_name, categories.parent_id FROM categories_description, categories WHERE  categories_description.categories_id = categories.categories_id AND categories.parent_id='$nt2[categories_id]'"); 
while($nt3=mysql_fetch_array($q3)){ 
echo "addOption(document.drop_list.SubCat,'$nt3[categories_id]', '$nt3[categories_name]');"; 


} // end of while loop 
echo "}"; // end of JS if condition 

} 
?> 
} 
//////////////////  

function removeAllOptions(selectbox) 
{ 
    var i; 
    for(i=selectbox.options.length-1;i>=0;i--) 
    { 
        //selectbox.options.remove(i); 
        selectbox.remove(i); 
    } 
} 


function addOption(selectbox, value, text ) 
{ 
    var optn = document.createElement("OPTION"); 
    optn.text = text; 
    optn.value = value; 

    selectbox.options.add(optn); 
} 

 

The question is how can we get the value catogories_id from getit.php file so we can use it in test.html file. I'm really need this so if anyone know please help me. Any help will be greatly appriciate.

 

Thank you

vanvoquan

Thanks for helping me out Progr@mmer. I'm new to php and what you said is impossible for me to do. All i want is after I click the submit button my browser url look like this:

http://localhost/thu3/index.php?Category=61_62

 

But for now my browser url is like this:

http://localhost/thu3/index.php?Category=61&Subcat=62

Is that possible we can throw out this "&Subcat=" and add this "_" between the categorie_id and the Subcat_id so all I have in the url is:

http://localhost/thu3/index.php?Category=61_62

Any suggestion will be appreciate!!

 

Thank you

vanvoquan

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.