Jump to content

reptile

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by reptile

  1. reptile, trust us, there is no way for PHP and JavaScript to directly interact except through AJAX.  If your JavaScript code isn't using XMLHttpRequest (or, even better, library code that makes it a hell of a lot easier to use out of the gate, like jQuery's $.get()), then it's not talking to the PHP on the server.

     

    The thing that looks like it's working is likely being pre-populated with data at the time of page request, with the JavaScript merely manipulating the DOM after it's been rendered.  In other words, it's an illusion, and not working the way you think it's working.

     

    So, again, just to drive the point home: no XMLHttpRequest object in your JS code/no using a library that wraps that object (like jQuery) = no direct communication between JS and PHP.

    Hmm... I see, I do know that once the page loads and then you select different selections in the dropdown (eg. Select distinct Division...) then the other dropdowns change because they depend on that select statement from the database.  I just can't get the one to work where 'Select Style' selects a style and then it should change the 'Select Front' selections or at least display them which it's not.

  2. onchange doesn't cause the page to refresh, So no request is being sent to the webserver (unless you have some javascript code that is refreshing the page).

    Yeah, there might be more to it.  PHP isn't something that I have much experience with but this is existing code that I have to modify at work.  Basically this code generates dropdown menus with data, so whenever a change is made in the selection then the function is called to display data in the other dropdown menus.  But the updateforBodyfitting isn't working.  So the "Select Front" changes depending on the selection in the "Select Style".

  3. Yes, but what code do you think is being executed when those functions are called using onchange a) Javascript, b) PHP or c) both?

    PHP scripts will only be activated when a request is made to the webserver and will cause a page to refresh, so from javscript's onchange event.  But I am just annoyed because one function is called while the other isn't, there is nothing different in the way they are being called.

  4. The browser is calling that function. Not PHP.

     

    Do you understand the difference between Javascript and PHP? And how/when these two languages are executed?

    Maybe I said it incorrectly then but both functions are being called by the browser.  Both at different "Onchange" events. Also yes I know that javascript works on the browser and php on the webserver.

  5. Read Kevins first point.. All what PHP is doing outputting the javascript code for defining the Updateforbodyfittingoptions javascript function, When you call this function the PHP code that defined it will not be called! 

    I see what you are saying, but how come the function "updateSelectClothByDiv(division)" is being called, this is also an onchange event?

  6. Hi,  I've highlighted the code in red below, it is not showing the output, although it does show the results when I view the source of the actual webpage (so looks to work), it should show a dropdown menu beginning with 'Select Front'  but I am getting an "objected expected" error, also this function "Updateforbodyfittingoptions" is called at the onchange event.

    I have a dropdown menu created from javascript, so the onchange event should call a function called updateForBodyfittingoptions(). The thing here is that this function updateForBodyfittingoptions() should actually run dependent on a loop that is part of another function called UpdateDivision.

    So if I were to put the function UpdateBodyfitting directly within the loop of the other function updateSelectClothByDiv(division) then I get "Object Expected".

     

    Remember the onchange calls the UpdateBodyfitting function.

    Here is the code which I've shortened for purposes of posting on here, I've also attached the main php file with all the code just in case anyone wants to reference it.
    , the main function is "generateUpdateSelectClothByDiv", within this function are "updateForBodyfittingoptions" and "updateSelectClothByDiv(division)".   Really appreciate any help I can get, thanks in advance.

     

    function generateUpdateSelectClothByDiv() {

    global $connect,$hriconnect,$division_array,$cloth_array,$lining_array,$lining_sleeve_array,$bodyfitting_array,$pantstyle_array,$veststyle_array,$glob_div;
    $indexdiv=1; $indexbody=1;
    //global $field1_array,$field2_array,$field4_array,$extras_array,$field5_array;

    // echo "\t\tdocument.pickDivision.bodyfitting.selectedIndex=-1;\n";
    $cloth_numrows = 0;
    $clothArray = array();
    $div_query = "SELECT distinct DIVISION, CLOTHDB FROM MTM_DIVISIONS_S ORDER BY CLOTHDB";
    $div_result = oci_parse($connect,$div_query);
    oci_execute($div_result);
    while ($div_row = oci_fetch_array($div_result, OCI_ASSOC)) {
    $divArray[] = "{$div_row['CLOTHDB']}";
    $divDivArray[] = "{$div_row['DIVISION']}";
    }

    oci_free_statement($div_result);
    // print("//TEST\n\n");
    echo "\tfunction updateSelectClothByDiv(division)\n";
    echo "\t{\n";
    $first = 0;

    echo "\tClearOptionsFastAlt('cloth');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    //echo "alert(divcomp)";
    for ($i = 0; $i < sizeof($divArray); $i++) {
    $cloth_query="SELECT CLOTH, CODE FROM ".$divArray[$i]." where CODE <>'OUT' or CODE is null ORDER BY cloth";

    $cloth_result = oci_parse($connect,$cloth_query);
    oci_execute($cloth_result);
    $cloth_numrows = count_rows($connect,$cloth_query);
    $maxclothrows=$cloth_numrows+1;

    $bodyfitting_query="SELECT BODYFITTING, BFCODE FROM MTM_STYLES_S WHERE DIVISION= '".$divDivArray[$i]."' AND STYLE_TYPE='BODY' GROUP BY BODYFITTING, BFCODE ORDER BY BODYFITTING";
    $bodyfitting_result = oci_parse($connect,$bodyfitting_query);
    oci_execute($bodyfitting_result);
    $bodyfitting_numrows = count_rows($connect,$bodyfitting_query);
    $maxclothrows=$bodyfitting_numrows+1;


    if($first == 0) {
    $first++;
    } else {
    echo "\telse\t";
    }
    //echo "\talert('$divArray[$i]' +' '+ '$divDivArray[$i]'+' :aaa:' + divcomp);";
    echo "\tif (divcomp == \"{$divDivArray[$i]}\") {";

    $y=1;
    echo "var selectObj = document.pickDivision.cloth;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Cloth -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($cloth_row = oci_fetch_array($cloth_result, OCI_ASSOC)) {
    $newCloth=$cloth_row['CODE'];
    $newStyle=$cloth_row['CLOTH'];
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newStyle.' '.$newCloth."', '".$newStyle."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;
    }
    echo "\t\t\tdocument.pickDivision.cloth.options[0].selected = true;\n\n";

    echo "\tClearOptionsFastAlt('lining');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    echo "var selectObj = document.pickDivision.lining;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Lining -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($lining_row = oci_fetch_array($lining_result, OCI_ASSOC)) {
    $newLining=$lining_row['CLOTH'];
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newLining."' ,'".$newLining."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;
    }
    echo "\t\t\tdocument.pickDivision.lining.options[0].selected = true;\n\n";


    //Setup new dropdown for Style Selection
    echo "\tClearOptionsFastAlt('bodyfitting');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    echo "var selectObj = document.pickDivision.bodyfitting;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Style -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($bodyfitting_row = oci_fetch_array($bodyfitting_result, OCI_ASSOC)) {
    $newBodyfitting=$bodyfitting_row['BODYFITTING'];
    $newBfcode=$bodyfitting_row['BFCODE'];
    $bodyfitArray[] = "{$bodyfitting_row['BFCODE']}";
    $bodyfitbodyarray[]="{$bodyfitting_row['BODYFITTING']}";
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newBfcode.' '.$newBodyfitting."', '".$newBfcode."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;

    echo "\tfunction updateForBodyfittingoptions()\n";
    echo "\t{\n";



    echo "\t\tif(document.pickDivision.bodyfitting.options.value == '{$bodyfitting_row['BFCODE']} {$bodyfitting_row['BODYFITTING']}')\n";
    echo "\t\t{\n";

    //Show selection for front
    $field1_query = "SELECT MTM_STYLES_S.CODE,MTM_SUFFEX_S.TEXT FROM MTM_STYLES_S,MTM_SUFFEX_S WHERE MTM_SUFFEX_S.DIVISION='".$divDivArray[$i]."' AND (MTM_STYLES_S.FIELD=MTM_SUFFEX_S.FIELD AND MTM_STYLES_S.CODE=MTM_SUFFEX_S.CODE) AND MTM_STYLES_S.STYLE_TYPE='BODY' AND MTM_STYLES_S.BODYFITTING='".$bodyfitting_row['BODYFITTING']."' AND MTM_STYLES_S.FIELD=1 ORDER BY MTM_STYLES_S.FIELD,MTM_STYLES_S.CODE";
    $field1_result = oci_parse($connect,$field1_query);
    oci_execute($field1_result);
    echo "\t\t\tdocument.pickDivision.field1.options[0].value = '';\n";
    echo "\t\t\tdocument.pickDivision.field1.options[0].text = '- Select Front';\n\n";
    $y=1;


    while ($field1_row = oci_fetch_array($field1_result, OCI_ASSOC)) {
    $newField1=$field1_row['TEXT'];
    $newField1Code=$field1_row['CODE'];
    $bodyfitArray[] = "{$bodyfitting_row['BFCODE']}";
    $bodyfitbodyarray[]="{$bodyfitting_row['BODYFITTING']}";
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newField1Code.' '.$newField1."', '".$newField1Code."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;

    }
    echo "\t\t\tdocument.pickDivision.field1.options[0].selected=true;\n\n";
    $indexfield1=1;
    oci_free_statement($field1_result);



    echo "\t\t}\n\n";
    echo "\t\t}\n\n";
    }
    echo "\t\t\tdocument.pickDivision.bodyfitting.options[0].selected=true;\n\n";


    echo "\t}\n\n";


    oci_free_statement($bodyfitting_result);
    $indexbody=1;


    oci_free_statement($cloth_result);

    }
    $indexdiv++;
    echo "\t\treturn true;\n";
    echo "\t}\n\n";



    oci_close($connect);

    }

  7. I have a dropdown menu created from javascript, so the onchange event should call a function called updateForBodyfittingoptions(). The thing here is that this function updateForBodyfittingoptions() should actually run dependent on a loop that is part of another function called UpdateDivision.

    So if I were to put the function UpdateBodyfitting directly within the loop of the other function updateSelectClothByDiv(division) then I get "Object Expected".

     

    Remember the onchange calls the UpdateBodyfitting function.

    Here is the code which I've shortened for purposes of posting on here, I've also attached the main php file with all the code just in case anyone wants to reference it.
    , the main function is "generateUpdateSelectClothByDiv", within this function are "updateForBodyfittingoptions" and "updateSelectClothByDiv(division)".   Really appreciate any help I can get, thanks in advance.

     

    function generateUpdateSelectClothByDiv() {

    global $connect,$hriconnect,$division_array,$cloth_array,$lining_array,$lining_sleeve_array,$bodyfitting_array,$pantstyle_array,$veststyle_array,$glob_div;
    $indexdiv=1; $indexbody=1;
    //global $field1_array,$field2_array,$field4_array,$extras_array,$field5_array;

    // echo "\t\tdocument.pickDivision.bodyfitting.selectedIndex=-1;\n";
    $cloth_numrows = 0;
    $clothArray = array();
    $div_query = "SELECT distinct DIVISION, CLOTHDB FROM MTM_DIVISIONS_S ORDER BY CLOTHDB";
    $div_result = oci_parse($connect,$div_query);
    oci_execute($div_result);
    while ($div_row = oci_fetch_array($div_result, OCI_ASSOC)) {
    $divArray[] = "{$div_row['CLOTHDB']}";
    $divDivArray[] = "{$div_row['DIVISION']}";
    }

    oci_free_statement($div_result);
    // print("//TEST\n\n");
    echo "\tfunction updateSelectClothByDiv(division)\n";
    echo "\t{\n";
    $first = 0;

    echo "\tClearOptionsFastAlt('cloth');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    //echo "alert(divcomp)";
    for ($i = 0; $i < sizeof($divArray); $i++) {
    $cloth_query="SELECT CLOTH, CODE FROM ".$divArray[$i]." where CODE <>'OUT' or CODE is null ORDER BY cloth";

    $cloth_result = oci_parse($connect,$cloth_query);
    oci_execute($cloth_result);
    $cloth_numrows = count_rows($connect,$cloth_query);
    $maxclothrows=$cloth_numrows+1;

    $bodyfitting_query="SELECT BODYFITTING, BFCODE FROM MTM_STYLES_S WHERE DIVISION= '".$divDivArray[$i]."' AND STYLE_TYPE='BODY' GROUP BY BODYFITTING, BFCODE ORDER BY BODYFITTING";
    $bodyfitting_result = oci_parse($connect,$bodyfitting_query);
    oci_execute($bodyfitting_result);
    $bodyfitting_numrows = count_rows($connect,$bodyfitting_query);
    $maxclothrows=$bodyfitting_numrows+1;


    if($first == 0) {
    $first++;
    } else {
    echo "\telse\t";
    }
    //echo "\talert('$divArray[$i]' +' '+ '$divDivArray[$i]'+' :aaa:' + divcomp);";
    echo "\tif (divcomp == \"{$divDivArray[$i]}\") {";

    $y=1;
    echo "var selectObj = document.pickDivision.cloth;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Cloth -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($cloth_row = oci_fetch_array($cloth_result, OCI_ASSOC)) {
    $newCloth=$cloth_row['CODE'];
    $newStyle=$cloth_row['CLOTH'];
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newStyle.' '.$newCloth."', '".$newStyle."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;
    }
    echo "\t\t\tdocument.pickDivision.cloth.options[0].selected = true;\n\n";

    echo "\tClearOptionsFastAlt('lining');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    echo "var selectObj = document.pickDivision.lining;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Lining -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($lining_row = oci_fetch_array($lining_result, OCI_ASSOC)) {
    $newLining=$lining_row['CLOTH'];
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newLining."' ,'".$newLining."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;
    }
    echo "\t\t\tdocument.pickDivision.lining.options[0].selected = true;\n\n";


    //Setup new dropdown for Style Selection
    echo "\tClearOptionsFastAlt('bodyfitting');\n";
    echo "\t\tdocument.pickDivision.textInput.value='';\n";
    echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
    echo "var selectObj = document.pickDivision.bodyfitting;\n";
    echo "var numShown = selectObj.options.length;\n";
    echo "selectObj.selectedIndex = -1;\n";
    echo "\t\t\tselectObj.options[numShown] = new Option('- Select Style -', '');\n";
    echo "\t\t\tnumShown++;\n";
    while ($bodyfitting_row = oci_fetch_array($bodyfitting_result, OCI_ASSOC)) {
    $newBodyfitting=$bodyfitting_row['BODYFITTING'];
    $newBfcode=$bodyfitting_row['BFCODE'];
    $bodyfitArray[] = "{$bodyfitting_row['BFCODE']}";
    $bodyfitbodyarray[]="{$bodyfitting_row['BODYFITTING']}";
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newBfcode.' '.$newBodyfitting."', '".$newBfcode."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;

    echo "\tfunction updateForBodyfittingoptions()\n";
    echo "\t{\n";


    echo "\t\tif(document.pickDivision.bodyfitting.options.value == '{$bodyfitting_row['BFCODE']} {$bodyfitting_row['BODYFITTING']}')\n";
    echo "\t\t{\n";

    //Show selection for front
    $field1_query = "SELECT MTM_STYLES_S.CODE,MTM_SUFFEX_S.TEXT FROM MTM_STYLES_S,MTM_SUFFEX_S WHERE MTM_SUFFEX_S.DIVISION='".$divDivArray[$i]."' AND (MTM_STYLES_S.FIELD=MTM_SUFFEX_S.FIELD AND MTM_STYLES_S.CODE=MTM_SUFFEX_S.CODE) AND MTM_STYLES_S.STYLE_TYPE='BODY' AND MTM_STYLES_S.BODYFITTING='".$bodyfitting_row['BODYFITTING']."' AND MTM_STYLES_S.FIELD=1 ORDER BY MTM_STYLES_S.FIELD,MTM_STYLES_S.CODE";
    $field1_result = oci_parse($connect,$field1_query);
    oci_execute($field1_result);
    echo "\t\t\tdocument.pickDivision.field1.options[0].value = '';\n";
    echo "\t\t\tdocument.pickDivision.field1.options[0].text = '- Select Frontaaa';\n\n";
    $y=1;


    while ($field1_row = oci_fetch_array($field1_result, OCI_ASSOC)) {
    $newField1=$field1_row['TEXT'];
    $newField1Code=$field1_row['CODE'];
    $bodyfitArray[] = "{$bodyfitting_row['BFCODE']}";
    $bodyfitbodyarray[]="{$bodyfitting_row['BODYFITTING']}";
    echo "\t\t\tselectObj.options[numShown] = new Option('".$newField1Code.' '.$newField1."', '".$newField1Code."');\n";
    echo "\t\t\tnumShown++;\n";
    $y++;
    }
    echo "\t\t\tdocument.pickDivision.field1.options[0].selected=true;\n\n";
    $indexfield1=1;
    oci_free_statement($field1_result);



    echo "\t\t}\n\n";
    echo "\t\t}\n\n";
    }
    echo "\t\t\tdocument.pickDivision.bodyfitting.options[0].selected=true;\n\n";


    echo "\t}\n\n";


    oci_free_statement($bodyfitting_result);
    $indexbody=1;


    oci_free_statement($cloth_result);

    }
    $indexdiv++;
    echo "\t\treturn true;\n";
    echo "\t}\n\n";



    oci_close($connect);

    }

    mtm.php

  8. Hello everyone,

        I am having a pretty basic problem.  Below is a piece of my code, the first few lines of "Get Value for Bodyfitting" basically gets a value and assigns it to some variables through a select statement (this later on you will see that the values are being shown through echo on the screen in a form of a javascript dropdown for "Style Selection"), now the second few lines is where I have some issues in the "Value for Field 1", I want to get back a value by getting the answer from the first sql but I can't get the value for "$newBodyfitting" because it is only assigned later on, this will allow me to get a dropdown for a "Select Front", this is dependent on the "Select Style" if you see below, I know it might sound confusing.  Thanks in advance.

        //Get Division
        $div_query = "SELECT distinct DIVISION, CLOTHDB FROM MTM_DIVISIONS_S ORDER BY CLOTHDB";    
        $div_result = oci_parse($connect,$div_query);
        oci_execute($div_result);
        while ($div_row = oci_fetch_array($div_result, OCI_ASSOC)) {
          $divArray[] = "{$div_row['CLOTHDB']}";
          $divDivArray[] = "{$div_row['DIVISION']}";
        }
        oci_free_statement($div_result);
        //Get Value for Bodyfitting
        $bodyfitting_query="SELECT BODYFITTING, BFCODE FROM MTM_STYLES_S WHERE DIVISION= '".$divDivArray[$i]."' AND STYLE_TYPE='BODY' GROUP BY BODYFITTING, BFCODE ORDER BY BODYFITTING";   
        $bodyfitting_result = oci_parse($connect,$bodyfitting_query);
        oci_execute($bodyfitting_result);
       
        
        //Get Value for Field1
        $field1_query="SELECT MTM_STYLES_S.CODE,MTM_SUFFEX_S.TEXT FROM MTM_STYLES_S,MTM_SUFFEX_S WHERE MTM_SUFFEX_S.DIVISION='".$divDivArray[$i]."' AND      (MTM_STYLES_S.FIELD=MTM_SUFFEX_S.FIELD AND MTM_STYLES_S.CODE=MTM_SUFFEX_S.CODE) AND MTM_STYLES_S.STYLE_TYPE='BODY' AND MTM_STYLES_S.BODYFITTING='".$newBodyfitting."' AND MTM_STYLES_S.FIELD=1 ORDER BY MTM_STYLES_S.FIELD,MTM_STYLES_S.CODE";
        $field1_result = oci_parse($connect,$field1_query);
        oci_execute($field1_result);
    
        //Setup new dropdown for Style Selection
        echo "\tClearOptionsFastAlt('bodyfitting');\n";
        echo "\t\tdocument.pickDivision.textInput.value='';\n";
        echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
        echo "var selectObj = document.pickDivision.bodyfitting;\n";
        echo "var numShown = selectObj.options.length;\n";
        echo "selectObj.selectedIndex = -1;\n";
        echo "\t\t\tselectObj.options[numShown] = new Option('- Select Style -', '');\n";
        echo "\t\t\tnumShown++;\n";
        while ($bodyfitting_row = oci_fetch_array($bodyfitting_result, OCI_ASSOC)) {
            $newBodyfitting=$bodyfitting_row['BODYFITTING'];
            $newBfcode=$bodyfitting_row['BFCODE'];
            echo "\t\t\tselectObj.options[numShown] = new Option('".$newBfcode.' '.$newBodyfitting."', '".$newBfcode."');\n";
          echo "\t\t\tnumShown++;\n";      
          $y++;
         }
         
        //Setup dropdown new Front dependent on Style above
        echo "\t\t\tdocument.pickDivision.bodyfitting.options[0].selected = true;\n\n";
        echo "\t\tdocument.pickDivision.field1;\n";
        echo "\tClearOptionsFastAlt('field1');\n";
        echo "\t\tdocument.pickDivision.textInput.value='';\n";
        echo "var divcomp = division.replace(/^\s+|\s+$/g, '');";
        echo "var selectObj = document.pickDivision.field1;\n";
        echo "var numShown = selectObj.options.length;\n";
        echo "selectObj.selectedIndex = -1;\n";
        echo "\t\t\tselectObj.options[numShown] = new Option('- Select Front -', '');\n";
        echo "\t\t\tnumShown++;\n";
        
        while ($field1_row = oci_fetch_array($field1_result, OCI_ASSOC)) {
            $newField1=$field1_row['TEXT'];
            $newField2=$field2_row['CODE'];
            echo "\t\t\tselectObj.options[numShown] = new Option('".$newField1.''.$newField2."');\n";
          echo "\t\t\tnumShown++;\n";      
          $y++;
        }
       
           echo "\t\t\tdocument.pickDivision.field1.options[0].selected=true;\n\n";
           
           oci_free_statement($field1_result);
           oci_free_statement($bodyfitting_result);
  9.  

    I was sure that one (#11) would work.

     

    I set up a small test page

    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
     $( document ).ready(function() {
            removeBlanks();
     })
     
    
    function removeBlanks()
     {
         var size = document.form1.sel1.options.length;
         for (var i=0; i<size; i++) {
             if (document.forms[0].sel1.options[i].text=='') {
                 document.forms[0].sel1.options[i] = null;
             }
         }
     }
    </script>
    </head>
    <body>
        <form name='form1'>
            <select name='sel1'>
                <option value='1'></option>
                <option value='2'>2</option>
                <option value='3'></option>
                <option value='4'>4</option>
            </select>
        </form>
    </body>
    </html>
    

    Note options 1 and 3 have no text to appear in the dropdown.

     

    After loading and the removeBlanks() function has run, Firebug shows this, with the blanks removed

    <body>
    <form name="form1">
    <select name="sel1">
    <option value="2">2</option>
    <option value="4">4</option>
    </select>
    </form>
    </body>
    

    Your logic seems correct for sure, unfortunately it's not working for me so there has to be more to it in the code, yours does work just not in my program because as Josh mentioned there seems to be more afterwards.  I've put code in my previous post where values are inserted from the database.

  10. sorry to jump in here, but your approach is backwards. you are creating $maxclothrows empty entries at one point, apparently putting some values in an another point, and wanting to remove the remaining empty entires after the point where you have put in the actual data.

     

    the correct approach would be to initialize/create just the entries you need at the point where the actual values are being retrieved at. why can you not do this directly? and if you did have a need to first create $maxclothrows empty entries, the place in the code where you would test for and remove the remaining empty ones would be right after the point where you have put in the actual data.

     

    so, what is your code that is putting in the actual data values?

    This is part of another while loop, but the basic code is here to print all the cloth selections dependent on the division (option the user can choose, there are 2 to choose from).

        // Print all cloth choices for the given division

        $cloth_query = "SELECT cloth,code FROM ".strtolower($division_row['CLOTHDB'])." ORDER BY CLOTH";

        $cloth_result = oci_parse($connect,$cloth_query);

        oci_execute($cloth_result);

        $cloth_numrows = count_rows($connect,$cloth_query);

        echo "\t\t\tdocument.pickDivision.cloth.options[0].value = '';\n";

        echo "\t\t\tdocument.pickDivision.cloth.options[0].text = '- Select Cloth -';\n\n";

        $y=1;

         while ($cloth_row = oci_fetch_array($cloth_result, OCI_ASSOC)) {

             $clothArray[] = "{$cloth_row['CLOTH']}";

            $cloth_array[$indexdiv][$indexcloth]="{$cloth_row['CLOTH']} {$cloth_row['CODE']}";    

          echo "\t\t\tdocument.pickDivision.cloth.options[$y].value = '{$cloth_row['CLOTH']} {$cloth_row['CODE']}';\n";

          echo "\t\t\tdocument.pickDivision.cloth.options[$y].text = '{$cloth_row['CLOTH']} {$cloth_row['CODE']}';\n\n";

          

          $y++; $indexcloth++;

        }

  11. Alternatively, if the options are coming from a database table, change the query so those with blank values are exluded.

    Thanks for your help thus far, that would be extremely easy to exclude nulls, the problem is this.  The dropdown list is dependent on an option selection.

    2 options for example, A and B.  If the user selects option A then lets say there are a max# of cloths that are brought back at 20.  Now when the user selects option B then max# of cloths brought back are 15.  So this is coded in a way that because option A has 5 more values then option B, to clear those extra values of option A away when option B is selected, those extra 5 values are nulled out or set to ' '.  This is the point where I would like to remove those extra 5 blank lines from the dropdown.  Hope that made sense?

  12. Okay well can you please define what "blank lines" means to you?

     

    Are you talking about removing the php lines of code that set javascript variables to empty string values?

     

    If so, then just open up the php file and remove them...now you see it:

     

    echo "\t\tfor(index=0; index < $maxclothrows; index++)\n";
    echo "\t\t{\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].text = '';\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].value = '';\n";
    echo "\t\t}\n\n";
    
    now you don't.

     

    echo "\t\tfor(index=0; index < $maxclothrows; index++)\n";
    echo "\t\t{\n";
    echo "\t\t}\n\n";
    
    OOR...are you saying this is exactly what you want to do, but you have like 3000 lines of code to go through, and want a simple way to find and remove them from the php source file? If this is the case, then I would advise against making it completely automatic. There's no guarantee that they are all in the format you listed above, and it sure would suck if you were to end up removing more than you intend..

     

    Instead, I would open the file in an editor that has a regex find and replace feature (that prompts you before actually replacing).

     

    But a regex like this should find the ones you listed above:

     

    echo\s*".*?=\s*''

     

    Sorry Josh again for not being too clear, what I mentioned to Cracka Memba above is what I want to do.

  13.  

    I think they are talking about removing blank entries from an HTML dropdown.  That JS is doing something to set the entries to '' so they appear as blank in the dropdown.

     

    Is this correct?

     

     

    Not tested:

    echo "\t\t\tdocument.pickDivision.cloth.remove(index);\n";

    Actually yes, that's it, they want to remove the blank lines that show up in the HTML dropdown.  The JS is indeed setting the entries coming from a database table to ' ', so they are appearing as blanks.  I tried to put your line above after the

    line: echo "\t\t\tdocument.pickDivision.cloth.options[index].value = '';\n";

    But it didn't work.  I will try again now.

  14. echo "\t\tfor(index=0; index < $maxclothrows; index++)\n";
    echo "\t\t\if(document.pickDivision.cloth.options[index].text != '')\n";   // <-------------- add
    echo "\t\t{\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].text = '';\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].value = '';\n";
    echo "\t\t}\n\n";

    Thanks Guru but it didn't work, existing code has it set to blank first and everyone wants those blanks to be removed.  You can see my explanation in the above post if it makes sense.

  15. what do you mean by "showing up in the list" ?

     

    It looks like you are using php to echo out some javascript to execute. Well you can't make php turn around and remove the code - it's already been sent to the browser. And even then you can't make javascript remove lines of code in the source. IOW "no takebacks".

    You are right Josh, the things is that it's a little weird the way this program was made, initially some values show up which need to be set to blank so that they don't show for  certain options chosen by the user.  So in the beginning I guess everyone was okay to see blank lines because in theory they don't have any value except null I guess, now they want those blank lines to be removed.  I read that preg_replace or str_replace can help?

  16. Hi,

       I have a little snipplet I am posting here, I am not very experienced with PHP but thought I would ask some of you for help.  I have to modify a program and a very small part of it is to remove lines where values are being set to blank or '' null values. Here is the little code snipplet:

     

    echo "\t\tfor(index=0; index < $maxclothrows; index++)\n";
    echo "\t\t{\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].text = '';\n";
    echo "\t\t\tdocument.pickDivision.cloth.options[index].value = '';\n";
    echo "\t\t}\n\n";

     

    This above code is used to set some values to ' ', but then after I would like those blank values removed rather then showing up in the list because when I scroll down you have a whole bunch of blank lines. How can I remove these completely?

    Maybe:

    echo "\t\t\if(document.pickDivision.cloth.options[index].text = '') {...some code here to remove this blank line}

    I read about regex or some str_replace, but am not sure how to use it.  This program is around 3000 lines of code, so don't think I can attach the file.  Any help would be greatly appreciated!

     

×
×
  • 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.