Auto updation problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gauravtechie
    New Member
    • Aug 2007
    • 1

    Auto updation problem

    Hi all,

    I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change,

    the code is

    [HTML]
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <SCRIPT language=JavaSc ript>
    function reload(form)
    {
    // Setting the variable with the value of selected country's ID
    var val=populate.ca talogue.options[populate.catalo gue.options.sel ectedIndex].value;
    self.location=' eform.php?catal ogueId=' + val;
    var val2=val+'&cate goryID='+popula te.category.opt ions[populate.catego ry.options.sele ctedIndex].value;
    self.location=' eform.php?catal ogueId=' + val2;
    var val3=val2+'&pro ductsID='+popul ate.products.op tions[populate.produc ts.options.sele ctedIndex].value;
    self.location=' eform.php?catal ogueId=' + val3;
    var val3=val2+'&qua ntityID='+popul ate.quantity.op tions[populate.quanti ty.options.sele ctedIndex].value;
    self.location=' eform.php?catal ogueId=' + val3;
    }
    JOptionPane.sho wMessageDialog( frame, "Eggs aren't supposed to be green.");
    </script>
    <?php
    function getCatalogueLis t()
    { $catalogue = array (
    '1' => 'Catalogue',
    '2' => 'Non - Catalogue',
    );
    return $catalogue;
    }
    function getCategoryList ($catalogueId)
    {
    $category= array (
    'Catalogue' => array ('CD', 'SD', 'AG', 'FD', 'CM', 'TB', 'GB', 'TG', 'MD', 'PD' ),
    );
    return $category[$catalogueId];
    }
    function getProductList( $categoryID)
    {
    $products= array (
    'CD' =>array ('CD001 ' , ' CD002 ' , ' CD003 ' , ' CD004 ' , ' CD005 ' , ' CD006 ' , ' CD007 ' , ' CD008 ' , ' CD009 ' , ' CD010 ' , ' CD011 ' , ' CD012 ' , ' CD013 ' , ' CD014 ' , ' CD015 ' , ' CD016 ' , ' CD017 ' , ' CD018 ' , ' CD019 ' , ' CD020 ' , ' CD021 ' , ' CD022 ' , ' CD023 ' , ' CD024 ' , ' CD025 ' , ' CD026 ' , ' CD027 ' , ' CD028 ' , ' CD029 ' , ' CD030 ' , ' CD031 ' , ' CD032 ' , ' CD033 ' , ' CD034 ' , ' CD035 ' , ' CD036 ' , ' CD037 ' , ' CD038 ' , ' CD039 ' , ' CD040 ' , ' CD041 ' , ' CD042 ' , ' CD043 ' , ' CD044 ' , ' CD045 ' , ' CD046 ' , ' CD047 ' , ' CD048 ' , ' CD049 ' , ' CD050 ' , ' CD051 ' , ' CD052 ' , ' CD053 ' , ' CD054 ' , ' CD055 ' , ' CD056 ' , ' CD057 ' , ' CD058 ' , ' CD059 ' , ' CD060 ' , ' CD061 ' , ' CD062'),

    'SD' => array (' SD001 ' , ' SD002 ' , ' SD003 ' , ' SD004 ' , ' SD005 ' , ' SD006 ' , ' SD007 ' , ' SD008 ' , ' SD009 ' , ' SD010 ' , ' SD011 ' , ' SD012 ' , ' SD013 ' , ' SD014 ' , ' SD015 ' , ' SD016 ' , ' SD017 ' , ' SD018 ' , ' SD019 ' , ' SD020 ' , ' SD021 ' , ' SD022 ' , ' SD023 ' , ' SD024 ' , ' SD025 ' , ' SD026 ' , ' SD027 ' , ' SD028 ' , ' SD029 ' , ' SD030 ' , ' SD031 ' , ' SD032 ' ),

    'FD' => array(' FD001 ' , ' FD002 ' , ' FD003 ' , ' FD004 ' , ' FD005 ' , ' FD006 ' , ' FD007 ' , ' FD008 ' , ' FD009 ' , ' FD010 ' , ' FD011 ' , ' FD012 ' , ' FD013 '),

    'AG' => array(' AG001 ' , ' AG002 ' , ' AG003 '),

    'GB' => array(' GB001 ' , ' GB002 ' , ' GB003 ' , ' GB004 ' , ' GB005 ' , ' GB006 ' , ' GB007 ' , ' GB008 ' , ' GB009 ' , ' GB010 ' , ' GB011 ' , ' GB012 ' , ' GB013 ' , ' GB014 ' , ' GB015 ' , ' GB016 ' , ' GB017 ' , ' GB018 ' , ' GB019 ' , ' GB020 ' , ' GB021 ' , ' GB022 '),

    'CM' => array(' CM001 ' , ' CM002 ' , ' CM003 ' , ' CM004 ' , ' CM005 ' , ' CM006 ' , ' CM007 ' , ' CM008 ' , ' CM009 ' , ' CM010 ' , ' CM011 ' , ' CM012 ' , ' CM013 ' , ' CM014 ' , ' CM015 ' , ' CM016 ' , ' CM017 ' , ' CM018 ' , ' CM019 ' , ' CM020 ' , ' CM021 ' , ' CM022 ' , ' CM023 ' , ' CM024 ' , ' CM025 ' , ' CM026 ' , ' CM027 ' , ' CM028 ' , ' CM029 ' , ' CM030 ' , ' CM031 ' , ' CM032 ' , ' CM033 '),

    'TB' => array( ' TB001 ' , ' TB002 ' , ' TB003 ' , ' TB004 ' , ' TB005 ' , ' TB006 ' , ' TB007 ' , ' TB008 ' , ' TB009 ' , ' TB010 ' , ' TB011 ' , ' TB012 ' , ' TB013 '),

    'TG' => array(' TG001 ' , ' TG002 ' , ' TG003 ' , ' TG004 ' , ' TG005 ' , ' TG006 ' , ' TG007 ' , ' TG008 ' , ' TG009 ' , ' TG010 ' , ' TG011 ' , ' TG012 ' , ' TG013 ' , ' TG014 ' , ' TG015 ' , ' TG016 ' , ' TG017 ' , ' TG018 ' , ' TG019 ' , ' TG020 ' , ' TG021 ' , ' TG022 ' ),

    'MD' => array(' MD001 ' , ' MD002 ' , ' MD003 ' , ' MD004 ' , ' MD005 ' , ' MD006 ' , ' MD007 ' , ' MD008 ' , ' MD009 ' , ' MD010 ' , ' MD011 '),

    'PD' => array( ' PD001 ' , ' PD002 ' , ' PD003 ' ),

    );
    return $products[$categoryID];
    }
    ?>

    <form action="eform.p hp" name="populate" method="post">
    <?
    // Retrieving the country list
    $catalogue = getCatalogueLis t();

    // Setting the variable if the country is selected for its city list
    @$catalogueId = $_GET['catalogueId'];
    @$categoryID = $_GET['categoryID'];
    @$productsID = $_GET['productsID'];

    // Retrieving the city list if a country is selected
    $category= ($catalogueId) ? getCategoryList ($catalogueId) : null;
    $products= ($categoryID) ? getProductList( $categoryID) : null;
    if (!empty($catalo gue))
    {
    // Generating the catalogue drop down menu
    echo "<select onChange='reloa d(this.form)' name='catalogue '>";
    foreach ($catalogue as $value)
    {
    echo "<option value='$value'" ;
    if ($catalogueId == $value)
    echo "selected";
    echo ">$value</option>";

    }
    echo "</select>";
    }
    if (!empty($catego ry))
    {
    // Generating the category drop down menu if a catalogue is selected
    echo "<select onChange='reloa d(this.form)' name='category' >";
    foreach ($category as $value)
    {
    echo "<option value='$value'" ;
    if ($categoryID == $value)
    echo "selected";
    echo ">$value</option>";
    }
    echo "</select>";
    }
    if (!empty($produc ts))
    {
    // Generating the products drop down menu if a country is selected
    echo "<select onChange='reloa d(this.form)' name='products' >";
    foreach ($products as $value)
    {
    echo "<option value='$value'" ;
    if ($productsID== $value)
    echo "selected";
    echo ">$value</option>";
    }
    echo "</select>";
    }
    ?>
    </body>
    </html>
    [/HTML]

    I want the Product also to be resetted on changing the catalgoue value
    Last edited by gits; Aug 30 '07, 01:28 PM. Reason: added code tags
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    Hi,

    Welcome to TSDN...

    Just have to ask a few questions first as I am not fluent with PHP so I want to make sure that I understand all the client side stuff.

    Whenever any of the selects (catalogue, category, products) are changed you refresh the page using the reload javascript. You then parse the values of the select boxes so that the values can be added into the querysring and you redirect the browser so that the page can be refreshed on the server side.

    If this is the case then there are a couple of issues that seem to effect this. Firstly you are repeatedly using the self.location property. You should avoid doing this as what would happen if that four calls to the server are issued, one for each of the self.location statements. If you build up your querystring and then do one self.location change this should improve the script.

    Secondly you try to use the value of an option for quantity, this does not seem to be in the HTML, in the javascript it also assigns this to val3 which is already used for category.

    I would try the javascript as follows:
    [CODE=javascript]
    function reload(form){

    // Setting the variable with the value of selected country's ID

    var $catalogue = populate.catalo gue.options[populate.catalo gue.options.sel ectedIndex].value;

    var $category = populate.catego ry.options[populate.catego ry.options.sele ctedIndex].value;

    var $products populate.produc ts.options[populate.produc ts.options.sele ctedIndex].value;

    self.location=' eform.php?catal ogueId=' + $catalogue + '&categoryID= ' + $category + '&products=' + $products;
    }
    [/CODE]

    I have loaded the values of the options into variables and then built up the redirection URL and done the redirect the once.

    Hope this helps

    P.S. The dollar notation is just something that I use to help distinguish variables in javascript and make sure that I don't use any reserved words for variable names. It will not interfere with the PHP.

    Comment

    Working...