Current location: Hot Scripts Forums » Programming Languages » PHP » popup problem


popup problem

Reply
  #1 (permalink)  
Old 02-01-07, 03:05 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
popup problem

I have a problem to complem my work at popup window this problem is I work at script allow the user to change a category place from one group to other and the category also have a sub inside it so the user can change the sub too. but I have a three dropdown list one for the group the secand for the category and the third for the sub category so he have to select the category and then he press at button to display anther three list to select where he want to move the category.

I send with this problem my code beacuse maybe the code will explain better than me.
PHP Code:

<html>

              <!--DropDown List Code-->
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.Group_Sub.options[form.Group_Sub.options.selectedIndex].value; 
self.location='<? echo $_SERVER['PHP_SELF']; ?>?cat=' + val ;
}
function reload3(form)
{
var val=form.Group_Sub.options[form.Group_Sub.options.selectedIndex].value; 
var val2=form.Cat_list.options[form.Cat_list.options.selectedIndex].value; 

self.location='<? echo $_SERVER['PHP_SELF']; ?>?cat=' + val + '&cat3=' + val2 ;
}
</script>

<SCRIPT language=JavaScript>
function reload2(form)
{
var val3=form.Group_Sub1.options[form.Group_Sub1.options.selectedIndex].value; 
self.location='<? echo $_SERVER['PHP_SELF']; ?>?show=1&cat1=' + val3 ;
}
function reload4(form)
{
var val3=form.Group_Sub1.options[form.Group_Sub1.options.selectedIndex].value; 
var val4=form.Cat_list1.options[form.Cat_list1.options.selectedIndex].value; 

self.location='<? echo $_SERVER['PHP_SELF']; ?>?show=1&cat1=' + val3 + '&cat4=' + val4 ;
}
</script>

<SCRIPT language=JavaScript>
function reload5(form)
{
var val3=form.Group_Sub2.options[form.Group_Sub2.options.selectedIndex].value; 
self.location='<? echo $_SERVER['PHP_SELF']; ?>?show_c=1&cat5=' + val3 ;
}
function reload6(form)
{
var val3=form.Group_Sub2.options[form.Group_Sub2.options.selectedIndex].value; 
var val4=form.Cat_list2.options[form.Cat_list2.options.selectedIndex].value; 

self.location='<? echo $_SERVER['PHP_SELF']; ?>?show_c=1&cat5=' + val3 + '&cat6=' + val4 ;
}
</script>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Page</title>
<style type="text/css">
<!--
body,td,th {
    SCROLLBAR-BASE-COLOR: #465779;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
a {
text-decoration: none; COLOR: #D7D7D7
}
-->
</style>
</head>
<?
   
require_once("lib/mysql.class.php");
   
$mysql_conn = new mysql;
   
$mysql_conn->connect( );
   
$mysql_conn->select_db(*******);
   
   if(isset(
$_REQUEST['go']))
   {
    if (
$_REQUEST['Group_Sub']=="0" && $_REQUEST['Cat_list']=="0" && $_REQUEST['Sub_list']=="0")
     {
       
$select_Note="Select the Group, the Category or the Sub Category that you want to Check it.";
     }
     elseif (
$_REQUEST['Group_Sub'] !="0" && $_REQUEST['Cat_list']=="0" && $_REQUEST['Sub_list']=="0")
     {
       
$value="select * from group_tbl where groupID='{$_REQUEST['Group_Sub']}'";
       
$run_value=$mysql_conn->query($value);
       
$dis=$mysql_conn->fetch_array($run_value);
       
$rese=$dis['group'];
     }
     elseif (
$_REQUEST['Group_Sub'] !="0" && $_REQUEST['Cat_list'] !="0" && $_REQUEST['Sub_list']=="0")
     {
       
$value="select * from cat_tbl where catID='{$_REQUEST['Cat_list']}' && groupID='{$_REQUEST['Group_Sub']}'";
       
$run_value=$mysql_conn->query($value);
       
$dis=$mysql_conn->fetch_array($run_value);
       
$rese=$dis['cat'];
     }
     else
     {
       
$value="select * from sub_tbl where subID='{$_REQUEST['Sub_list']}'"
       
$run_value=$mysql_conn->query($value);
       
$dis=$mysql_conn->fetch_array($run_value);
       
$rese=$dis['sub'];
     }
   }
   
///////////////////////////Update Command/////////////////////////
   
if(isset($_REQUEST['update']))
   {
    if(
$_REQUEST['group'] !="0" && $_REQUEST['cat'] =="0" && $_REQUEST['sub'] =="0")
    {
     if(empty(
$_REQUEST['res']))
     {
      
$empty_Note="You can not save an empty Record";
     }
     else
     {
     
$up="update group_tbl set group='{$_REQUEST['res']}' where groupID='{$_REQUEST['group']}'";
     
$mysql_conn->query($up) or die(mysql_error());
     echo 
$up;
     
$update_Note="Your Change is Successfully Save";
     }
    }
    
    elseif(
$_REQUEST['group'] !="0" && $_REQUEST['cat'] !="0" && $_REQUEST['sub'] =="0")
    {
     if(empty(
$_REQUEST['res']))
     {
      
$empty_Note="You can not save an empty Record";
     }
     else
     {
     
$up="update cat_tbl set cat='{$_REQUEST['res']}' where catID='{$_REQUEST['cat']}'";
     
$mysql_conn->query($up);
     
$update_Note="Your Change is Successfully Save";
     }
    }
    
    else
    {
     if(empty(
$_REQUEST['res']))
     {
      
$empty_Note="You can not save an empty Record";
     }
     else
     {
     
$up="update sub_tbl set sub='{$_REQUEST['res']}' where subID='{$_REQUEST['sub']}'";
     
$mysql_conn->query($up);
     
$update_Note="Your Change is Successfully Save";
     }
    }
   }
   
/////////////////////////the End of Update Command////////////////
   
   /////////////////////////Drop Command////////////////////////////
   
if(isset($_REQUEST['drop']))
   {
    if(
$_REQUEST['group'] !="0" && $_REQUEST['cat'] =="0" && $_REQUEST['sub'] =="0")
    {
     
$del_g="delete from group_tbl where groupID={$_REQUEST['group']}";
     
$mysql_conn->query($del_g) or die();
     
$del_c="delete from cat_tbl where groupID={$_REQUEST['group']}";
     
$mysql_conn->query($del_c) or die();
     
$del_s="delete from sub_tbl where groupID={$_REQUEST['group']}";
     
$mysql_conn->query($del_s) or die();
     
$del_i="delete from items_tbl where groupID={$_REQUEST['group']}";
     
$mysql_conn->query($del_i) or die();
     
$del_Note="Delete Gourp is Sccessfully delete with it's Category and Sub-Category";
    }
    
    elseif(
$_REQUEST['group'] !="0" && $_REQUEST['cat'] !="0" && $_REQUEST['sub'] =="0")
    {
     
$del_c="delete from cat_tbl where catID={$_REQUEST['cat']}";
     
$mysql_conn->query($del_c) or die();
     
$del_s="delete from sub_tbl where catID={$_REQUEST['cat']}";
     
$mysql_conn->query($del_s) or die();
     
$del_i="delete from items_tbl where catID={$_REQUEST['cat']}";
     
$mysql_conn->query($del_i) or die();
     
$del_Note="Delete Category is Sccessfully delete with it's Sub-Category";
    }
    
    else
    {
     
$del_s="delete from sub_tbl where subID={$_REQUEST['sub']}";
     
$mysql_conn->query($del_s) or die();
     
$del_i="delete from items_tbl where subID={$_REQUEST['sub']}";
     
$mysql_conn->query($del_i) or die();
     
$del_Note="Delete sub-Category is Sccessfully Done";
    }
   }
   
   
///////// Getting the data from Mysql table for first list box//////////
$quer2=$mysql_conn->query("SELECT DISTINCT * FROM group_tbl"); 
/////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl where groupID=$cat order by cat"); 
}
//else{$quer=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl order by cat"); } 
////////// end of query for second subcategory drop down list box ///////////////////////////

/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
$cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl where catID=$cat3 order by sub"); 
}
//else{$quer3=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl order by sub"); } 
////////// end of query for third subcategory drop down list box ///////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Drop Down oky//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////// Getting the data from Mysql table for first list box//////////
$quer4=$mysql_conn->query("SELECT DISTINCT * FROM group_tbl"); 
/////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat1=$HTTP_GET_VARS['cat1']; // This line is added to take care if your global variable is off
if(isset($cat1) and strlen($cat1) > 0){
$quer5=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl where groupID=$cat1 order by cat"); 
}
//else{$quer=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl order by cat"); } 
////////// end of query for second subcategory drop down list box ///////////////////////////

/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
$cat4=$HTTP_GET_VARS['cat4']; // This line is added to take care if your global variable is off
if(isset($cat4) and strlen($cat4) > 0){
$quer6=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl where catID=$cat4 order by sub"); 
}
//else{$quer3=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl order by sub"); } 
////////// end of query for third subcategory drop down list box ///////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Drop Down Move//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////// Getting the data from Mysql table for first list box//////////
$quer7=$mysql_conn->query("SELECT DISTINCT * FROM group_tbl"); 
/////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
$cat5=$HTTP_GET_VARS['cat5']; // This line is added to take care if your global variable is off
if(isset($cat5) and strlen($cat5) > 0){
$quer8=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl where groupID=$cat5 order by cat"); 
}
//else{$quer=$mysql_conn->query("SELECT DISTINCT * FROM cat_tbl order by cat"); } 
////////// end of query for second subcategory drop down list box ///////////////////////////

/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// 
$cat6=$HTTP_GET_VARS['cat6']; // This line is added to take care if your global variable is off
if(isset($cat6) and strlen($cat6) > 0){
$quer9=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl where catID=$cat6 order by sub"); 
}
//else{$quer3=$mysql_conn->query("SELECT DISTINCT * FROM sub_tbl order by sub"); } 
////////// end of query for third subcategory drop down list box ///////////////////////////

?>
<body bgcolor="#5F6F8F">
<h2 align="center">Edit Page</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
    <table width="76%" align="center">
   <tr>
        <td width="5%" style="font:bold">Group</td>
        <td width="1%">:</td>
        <td width="20%"><select name="Group_Sub" onChange="reload(this.form)">
                      <option value="0">Select Group Name</option>
                      <?
                         
while($fetch=$mysql_conn->fetch_array($quer2))
                         {
                           if(
$fetch['groupID']==@$cat)
                            {
                              echo 
"<option selected value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                           else 
                            {
                              echo 
"<option value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                         } 
                      
?>
      </select></td>
        <td width="1%">&nbsp;</td>
        <td width="8%" style="font:bold">Category</td>
        <td width="1%">:</td>
      <td width="18%"><select name="Cat_list" onChange="reload3(this.form)">
        <option value="0">Select Categoty</option>
        <?
                        
while($fetch_c=$mysql_conn->fetch_array($quer))
                         {
                           if(
$fetch_c['catID']==@$cat3)
                            {
                              echo 
"<option selected value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                           else
                            {
                              echo 
"<option  value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                         } 
                      
?>
      </select></td>
        <td width="1%">&nbsp;</td>
        <td width="23%" style="font:bold">Sub Category</td>
        <td width="1%">:</td>
        <td width="21%"><select name="Sub_list">
          <option value="0">Select Sub Categoty</option>
          <?
                  
while($dis2=$mysql_conn->fetch_array($quer3))
                    {
                      echo 
"<option value=\"{$dis2['subID']}\">{$dis2['sub']}</option>";
                    } 
                
?>
      </select></td>
    </tr>
    <input type="hidden" name="group" value="<? echo $_REQUEST['Group_Sub'];?>">
    <input type="hidden" name="cat" value="<? echo $_REQUEST['Cat_list'];?>">
    <input type="hidden" name="sub" value="<? echo $_REQUEST['Sub_list'];?>">
    <tr>
    <td colspan="11" align="center"><input type="submit" name="go" value="   Go   "></td></tr>
    <tr>
    <td colspan="11">&nbsp;</td></tr>
    <tr>
    <td colspan="11" align="center"><input type="text" name="res" size="40" value="<? echo $rese;?>"></td></tr>
    <tr>
      <td colspan="11" align="center"><input type="submit" name="update" value="Save Changes">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="drop" value="Drop it"></td>
      </tr>
    <tr>
      <td colspan="11" align="center">&nbsp;</td>
      </tr>
    <tr>
      <td colspan="11" align="center">&nbsp;</td>
      </tr>
    <tr>
    <td colspan="11" align="center"><a href="<? echo $_SERVER['PHP_SELF'];?>?show=1">Change Category OR Sub-Category Place</a></td>
    </tr>
    <tr>
    <?
     
if(isset($_REQUEST['show']))
     {
      echo 
"
            <td width=\"5%\" style=\"font:bold\">Group</td>
            <td width=\"1%\">:</td>
            <td width=\"20%\"><select name=\"Group_Sub1\" onChange=\"reload2(this.form)\">
                <option value=\"0\">Select Group Name</option>"
;
                         while(
$fetch=$mysql_conn->fetch_array($quer4))
                         {
                           if(
$fetch['groupID']==@$cat1)
                            {
                              echo 
"<option selected value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                           else 
                            {
                              echo 
"<option value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                         } 
      echo 
"</select></td>
        <td width=\"1%\">&nbsp;</td>
        <td width=\"8%\" style=\"font:bold\">Category</td>
        <td width=\"1%\">:</td>
        <td width=\"18%\"><select name=\"Cat_list1\" onChange=\"reload4(this.form)\">
        <option value=\"0\">Select Categoty</option>"
;
                        while(
$fetch_c=$mysql_conn->fetch_array($quer5))
                         {
                           if(
$fetch_c['catID']==@$cat4)
                            {
                              echo 
"<option selected value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                           else
                            {
                              echo 
"<option  value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                         } 
      echo 
"</select></td>
        <td width=\"1%\">&nbsp;</td>
        <td width=\"23%\" style=\"font:bold\">Sub Category</td>
        <td width=\"1%\">:</td>
        <td width=\"21%\"><select name=\"Sub_list1\">
          <option value=\"0\">Select Sub Categoty</option>"
;
                  while(
$dis2=$mysql_conn->fetch_array($quer6))
                    {
                      echo 
"<option value=\"{$dis2['subID']}\">{$dis2['sub']}</option>";
                    } 
      echo 
"</select></td>";
      echo 
"<tr><td colspan=\"11\" align=\"center\">
            <a href=\"
{$_SERVER['PHP_SELF']}?show_c=1\">OK</a>
            </td></tr>"
;
     }
//<input type=\"submit\" name=\"ok\" value=\"OK\">
     
?>
         <input type="hidden" name="m_group" value="<? echo $_REQUEST['Group_Sub1'];?>">
         <input type="hidden" name="m_cat" value="<? echo $_REQUEST['Cat_list1'];?>">
         <input type="hidden" name="m_sub" value="<? echo $_REQUEST['Sub_list1'];?>">
     <?
     
if(isset($_REQUEST['show_c']))
     {
      echo 
"
            <td width=\"5%\" style=\"font:bold\">Group</td>
            <td width=\"1%\">:</td>
            <td width=\"20%\"><select name=\"Group_Sub2\" onChange=\"reload5(this.form)\">
                <option value=\"0\">Select Group Name</option>"
;
                         while(
$fetch=$mysql_conn->fetch_array($quer7))
                         {
                           if(
$fetch['groupID']==@$cat5)
                            {
                              echo 
"<option selected value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                           else 
                            {
                              echo 
"<option value=\"{$fetch['groupID']}\">{$fetch['group']}</option>";
                            }
                         } 
      echo 
"</select></td>
        <td width=\"1%\">&nbsp;</td>
        <td width=\"8%\" style=\"font:bold\">Category</td>
        <td width=\"1%\">:</td>
        <td width=\"18%\"><select name=\"Cat_list2\" onChange=\"reload6(this.form)\">
        <option value=\"0\">Select Categoty</option>"
;
                        while(
$fetch_c=$mysql_conn->fetch_array($quer8))
                         {
                           if(
$fetch_c['catID']==@$cat6)
                            {
                              echo 
"<option selected value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                           else
                            {
                              echo 
"<option  value=\"{$fetch_c['catID']}\">{$fetch_c['cat']}</option>";
                            }
                         } 
      echo 
"</select></td>
        <td width=\"1%\">&nbsp;</td>
        <td width=\"23%\" style=\"font:bold\">Sub Category</td>
        <td width=\"1%\">:</td>
        <td width=\"21%\"><select name=\"Sub_list2\">
          <option value=\"0\">Select Sub Categoty</option>"
;
                  while(
$dis2=$mysql_conn->fetch_array($quer9))
                    {
                      echo 
"<option value=\"{$dis2['subID']}\">{$dis2['sub']}</option>";
                    } 
      echo 
"</select></td>";
     }
    
?>
    </tr>
</table>
<? echo $select_Note.$erorr.$update_Note.$empty_Note.$del_Note;?>
</form>
</body>
</html>
it is too long I am sorry but I realy need a help.
__________________
Their is no 100% secure system. ZCE
Reply With Quote
  #2 (permalink)  
Old 02-01-07, 11:56 AM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
mahmoud82,

I know you need the help but this is a lot to go through. Most folks who can solve this do it for a living. Is this something that you'd be willing to pay to have done? If so, post it in the "Job offers and Assistance" topic.

I've seen much more simple ways to do dynamic select boxes. Here is a decent one:

http://www.mattkruse.com/javascript/dynamicoptionlist/

There would be some more simple ajax code you could use as well.

Go here:

http://www.dhtmlgoodies.com/index.html?page=ajax

And look for "Chained select boxes"
__________________
"Things are difficult only while you don't understand them."
Reply With Quote
  #3 (permalink)  
Old 02-04-07, 03:17 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
hi grafman
I with you if I am not work with it but the problem that i do not explain good what I want I send a long code so anyone want to read it he will say ohh large code I do not want to spend my time for free, but what i exactly want that how can I save a hidden value while I move to anther section also I can not use form.
thanks for your link it is realy nice
__________________
Their is no 100% secure system. ZCE
Reply With Quote
  #4 (permalink)  
Old 02-04-07, 11:21 AM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
If you use the AJAX then you don't need to pass things from program to program because the browser page makes new requests without losing its original data.

I'm not sure why you couldn't pass a hidden variable to hold data, or you could create a javascript string to hold your data and pass that:

PHP Code:

print <<<ENDOFTEXT

var foo = 'asdf,qwer,2435,zxvc,ewrt,asdf';
function setSelectValue()
{
  //code to create the select function
}
ENDOFTEXT; 
The only other way is to pass it in session variables or cookies.
__________________
"Things are difficult only while you don't understand them."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
popup Problem dharprog JavaScript 4 11-01-06 07:12 AM
Problem with popup window in script Crizz JavaScript 5 04-27-06 06:45 PM
Problem with variable in Popup andreasberglind JavaScript 1 01-26-06 03:55 PM
problem in sending a form from a modal popup window davidklonski JavaScript 0 07-27-04 02:17 AM


All times are GMT -5. The time now is 05:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.