Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    i'm stuck and don't know how to code this logically...

    PHP Code:
    <script language="text/javascript">
        var CatID <? echo'= '$_GET['CatID']; ?>;
        var SectionID <? echo'= '$_GET['SectionID']; ?>;
        var SearchID <? echo'= '$_GET['SearchID']; ?>;
        
        var arrayurl = new Array(3);
        arrayurl[0] = "CatID";
        arrayurl[1] = "SectionID";
        arrayurl[2] = "SearchID";
        
        var useurlvar = "";    
        function urlvars() {
         for (i=0; i<3; i++) {
          if () {
           
          }
         //var url = "location.href=CatID=3&SectionID=advanced-search&SearchID=" + document.form1.select.options[document.form1.select.selectedIndex].value + ".php";
        }
    </script>
    The array has the list of variables that are in the url and i'm trying to use a for loop to loop through the arrays which have the variable names and see if the variable names are blank. In the future i will be adding more variables to the array to check. After it finds which ones are not empty add them to the useurlvar and the useurlvar will be used in the location.href....

    My logic is probably way off because i was going to use [I]if (arrayurl != "") but that will check to see if the array is blank which technically isn't because it has the variable name in it... I think I'm on the right track but can anyone help me out?

    -Thanks

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why not simply put the values to the elements of the array directly?

    var arrayurl = new Array(3);
    arrayurl[0] = "<? echo $_GET['CatID']; ?>"
    arrayurl[1] = "<? echo $_GET['SectionID']; ?>";
    arrayurl[2] = "<? echo $_GET['SearchID']; ?>";
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The array has the list of variables that are in the url and i'm trying to use a for loop to loop through the arrays which have the variable names and see if the variable names are blank. In the future i will be adding more variables to the array to check. After it finds which ones are not empty add them to the useurlvar and the useurlvar will be used in the location.href....
    Your example is confusing, because some of your variables are predefined:

    //var url = "location.href=CatID=3&SectionID=advanced-search&SearchID=" + document.form1.select.options[document.form1.select.selectedIndex].value + ".php";
    The script will depend on whether your form fields are required. If so, it would be easier to just check to see that they are filled in, alert if they are not, and don't submit the form until they are.

    If some of your variables really are predefined, just create hidden form fields containing the predefined values, and pass them in the url string:


    <form name="oFrm" method="get" action="http://www.myDomain.com/myScript.php">
    <input name="CatID" type="hidden" value="3" />
    <input name="SectionID" type="hidden" value="advanced-search" />
    <select name="SearchID">
    <option value="val1">Search Term 1</option>
    <option value="val2">Search Term 2</option>
    <option value="val3">Search Term 3</option>
    <option value="val4">Search Term 4</option>
    </select>
    <input name="oBtn" type="button" value="submit" onclick="javascript:this.form.submit();" />
    </form>

    var CatID <? echo'= '. $_GET['CatID']; ?>;
    var SectionID <? echo'= '. $_GET['SectionID']; ?>;
    var SearchID <? echo'= '. $_GET['SearchID']; ?>;
    These above can go in your php script:

    $CatID = $_GET[CatID];
    $SectionID = $_GET[SectionID];
    etc.

    But, again, if they are predefined:

    $CatID = 3;
    $SectionID = "advanced-search";
    etc.


    SearchID=" + document.form1.select.options[document.form1.select.selectedIndex].value + ".php"
    Your search term/ID is a select element, not text, so I don't know how you want to handle checking it, if at all. You would access it like this:

    //js

    function chkFrm(){
    var doc = document['oFrm']['SearchID'];
    alert (doc.options[doc.selectedIndex].value);
    }

    //end js

    Where is the code for your form???


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jamescover
    Your example is confusing, because some of your variables are predefined:



    The script will depend on whether your form fields are required. If so, it would be easier to just check to see that they are filled in, alert if they are not, and don't submit the form until they are.

    If some of your variables really are predefined, just create hidden form fields containing the predefined values, and pass them in the url string:


    <form name="oFrm" method="get" action="http://www.myDomain.com/myScript.php">
    <input name="CatID" type="hidden" value="3" />
    <input name="SectionID" type="hidden" value="advanced-search" />
    <select name="SearchID">
    <option value="val1">Search Term 1</option>
    <option value="val2">Search Term 2</option>
    <option value="val3">Search Term 3</option>
    <option value="val4">Search Term 4</option>
    </select>
    <input name="oBtn" type="button" value="submit" onclick="javascript:this.form.submit();" />
    </form>



    These above can go in your php script:

    $CatID = $_GET[CatID];
    $SectionID = $_GET[SectionID];
    etc.

    But, again, if they are predefined:

    $CatID = 3;
    $SectionID = "advanced-search";
    etc.




    Your search term/ID is a select element, not text, so I don't know how you want to handle checking it, if at all. You would access it like this:

    //js

    function chkFrm(){
    var doc = document['oFrm']['SearchID'];
    alert (doc.options[doc.selectedIndex].value);
    }

    //end js

    Where is the code for your form???


    -james
    i have // to echo out if that's what you wana call it.... my values will be predefined in the url but not all variables will be there, it depends on the links i press. I'm also not checking my form, i'm simply just checking to see if the varibles in my url excist or not and if they do then insert the variables used back into the url with the same values. The reason i'm doing this is because I'm creating a dynamic driven site and some variables will not always be used.

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    Why not simply put the values to the elements of the array directly?

    var arrayurl = new Array(3);
    arrayurl[0] = "<? echo $_GET['CatID']; ?>"
    arrayurl[1] = "<? echo $_GET['SectionID']; ?>";
    arrayurl[2] = "<? echo $_GET['SearchID']; ?>";
    this may seem a little confusing but I was hopeing to some how use the variable name in the array to see if the variable is empty not see if the array is empty... is this possible?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You can check each element of the array if it's empty or not, the same way you do in normal variables.

    if (arrayurl[0] == "") {
    //CatID is empty
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where is the code for your form???
    Your form?

    my values will be predefined in the url but not all variables will be there, it depends on the links i press.
    It would help to see the links as well. From what you've shown so far, I don't know why simple url encoding won't work, even for hyperlinks:

    <a href="http://www.myDomain.com/myScript.php?CatID=3&etc.">


    I think a more comprehensive description, along with your code so far--script, form, links, etc. would yield better results.


    this may seem a little confusing but I was hopeing to some how use the variable name in the array to see if the variable is empty not see if the array is empty... is this possible?

    It think you mean something like this:

    Code:
    <script type="text/javascript">
    <!--
    
    function chkFrm(){
    
    var doc = document['oFrm'];
    
    var oVal = []
    oVal[0] = doc['oTxt0'];
    oVal[1] = doc['oTxt1'];
    oVal[2] = doc['oTxt2'];
    
    for (var i=0;i<oVal.length;i++){
    alert ("Type: "+ oVal[i].type +"\n\r"+ "Value: "+ oVal[i].value);
    
    if (oVal[i].type == "text" && oVal[i].value == ""){
    alert("Please, complete all fields!");
    }
    }
    }
    
    //-->
    </script>
    
    
    <form name="oFrm">
    <input name="oTxt0" type="text" size="10" />
    <input name="oTxt1" type="text" size="10" />
    <input name="oTxt2" type="text" size="10" />
    <input name="oBtn" type="button" value="Check Form" onclick="javascript:chkFrm();" />
    </form>

    Just remove the first alert, and you can add any action you want in place of the second. At least, that should get you started...

    Or you can just check the form elements array. Hard to tell what you are doing without seeing all of your code.

    -james
    Last edited by jamescover; 08-19-2004 at 08:30 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #8
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <script language="text/javascript">
        var CatID <? echo'= '$_GET['CatID']; ?>;
        var SectionID <? echo'= '$_GET['SectionID']; ?>;
        var SearchID <? echo'= '$_GET['SearchID']; ?>;
        
        var arrayurl = new Array(3);
        arrayurl[0] = "CatID";
        arrayurl[1] = "SectionID";
        arrayurl[2] = "SearchID";
        
        var UseUrlVar = "";    
        function urlvars() {
         for (i=0; i<3; i++) {
          if (arrayurl[i] != "") {
           UseUrlVar+=arrayurl[i];
          }
         }
         alert(UseUrlVar);
        }
    </script>
    calling my function:
    <select name="select" onClick="javascript:Call urlvars;">

    my website functions through variables in the url whatever they are in the url i include the code using php for my page navigation... i'm working on the advanced search of my searching system... found here: http://www.maxforcepc.com/index.php?...dvanced-search I have a php error which i'll fix once i get this javascript issue fixed when you click the listbox and pick a category, right below that will change accordingly to the category

    I was testing out my code and i'm recieving this error:
    Error: missing ; before statement
    Source Code:
    javascript:Call urlvars;
    Last edited by DiarYofaMadmaN; 08-19-2004 at 07:41 PM.

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <select name="select" onclick="urlvars();">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    PHP Code:
    <script language="text/javascript">
    function search(sel) {
      sel.form.action += '&select=' + this.options[this.selectedIndex].value;
      sel.form.submit();
    }
    window.onload = init;
    function init() {
      var s_button = document.getElementById('search');
      s_button.parentNode.removeChild(s_button);
    }
    </script>
    ...
    <form action='advanced-search.php'>
      <input type='hidden' name='CatID' value='<?php echo $_GET['CatID']; ?>'>
      <input type='hidden' name='SearchID' value='<?php echo $_GET['SearchID']; ?>'>
      <select name="select" onChange="search(this);">
        <option value="None">None</option>
        <option value="Hardware">Hardware</option>
        <option value="Software">Software</option>
        <option value="Networking">Networking</option>
      </select>
      <input type='submit' value='Search' id='search'>
    </form>
    dumpfi
    Last edited by dumpfi; 08-20-2004 at 05:01 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •