One form triggering another
Results 1 to 9 of 9

Thread: One form triggering another

  1. #1
    Senior Member
    Join Date
    Sep 2012
    Posts
    269

    Arrow One form triggering another

    I have a 'multiple' form consisting of a field named 'System', and others. After a user selects a system in the list, I want another 'multiple' form to appear on the same page which is generated depending on the selected System.

    What language would be best to accomplish this? Would y'all point me in the right direction?

  2. #2
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    428
    What you're looking for is either AJAX or reloading the page.. I would recommend using AJAX. Trying searching for "php ajax form"... That should point you in the right direction.

    HTH
    Bob Lob Law

  3. #3
    Senior Member
    Join Date
    Sep 2012
    Posts
    269
    I've spent the whole day digging for answers and none are simple enough for what I need to do. All I need to do is pass one number from one <select> routine to another.

    Here's the code that will draw both fields:

    PHP Code:
    $host="localhost";
    $user="root";
    $password="*type password here**";
    $Dbname "CallsToDispatch";


    $cxn mysql_connect($host,$user,$password)
    or die (
    mysql_error() . "couldn’t connect to server");


    mysql_select_db($Dbname$cxn)
    or die(
    mysql_error() . "couldn't select database");


    echo 
    '<form name="SystemForm" action="Retrieve.php" method="post" >';

    echo 
    '<select name="SystemNum" size="8" multiple="multiple" style="text-align:left;">';



    echo 
    '<option value = "0">All Systems In Texoma</option>';



    $result mysql_query("SELECT * FROM Systems ORDER BY LongSystem");

    while(
    $row mysql_fetch_array($result))

                {
                    
    $SystemNum $row['SystemNum'];
                    echo 
    '<option value = "' $SystemNum '">' $row['LongSystem'] . '</option>';
                }
    echo 
    '</select>';

    // second box starts here

    echo '<div class = "center" style="width:400px; margin:auto">';

        echo 
    '<select name="TechNum" size="8" multiple="multiple" style="text-align:left;">';
        echo 
    '<option value="0">All Techs in System</option>';


    $result mysql_query("SELECT * FROM Techs"$cxn);
    $num_rows mysql_num_rows($result);
        
            if (
    $SystemNum == 67$Quest "SELECT * FROM Techs WHERE Contractor != ''";
            else 
    $Quest "SELECT * FROM Techs WHERE SystemNum = '$SystemNum' ORDER BY '$TechNum'";
             
    $result mysql_query($Quest$cxn)
                or die (
    'Santa Claus is watching you' mysql_error());

            while (
    $row mysql_fetch_array($result))
                { 
                    
    $FirstName $row['FirstName'];
                    
    $LastName $row['LastName'];
                    
    $TechNum $row['TechNum'];

                    echo 
    '<option value = "' $TechNum '">' $TechNum '--' $FirstName ' ' $LastName '</option>';
                }
        
    echo 
    '</select>';

    echo 
    '<br><br><input type="submit" value="Go" class = "FormButton" name = "Retrieve" style="font:24px Arial, Helvetica, sans-serif; font-weight:bold;">';

    echo 
    '</form>'
    All I need is to pass the value of "SystemNum" to the second <select> field, which will then be populated with the techs that are in that "SystemNum". Also, I don't want the second <select> to appear until the user makes his selection of "SystemNum"
    Last edited by timstring; 04-03-2013 at 05:50 PM.

  4. #4
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,784
    so if isset($_POST['FirstSelectBox']) then output the second select box? Also, did you look at ajax at all like he recommended? You'll have to trigger the post when the first select is chosen OR make it a 3 step process, first step select system, second step select tech, final step retrieve (whatever Retrive.php does).
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  5. #5
    Senior Member
    Join Date
    Sep 2012
    Posts
    269
    Did I look at ajax? I spent almost a whole day searching for AJAX answers, and everything I found was way too hefty for the seemingly small problem I have. I finally found the manual for jQuery, and there I have found some helpful hints.

    Thank you for the 'isset' hint.

  6. #6
    Senior Member
    Join Date
    Sep 2012
    Posts
    269

    Unhappy

    I shamelessly steal good stuff. Here's what I found @ good ole w3schools, which isn't working as it should.:

    Code:
    <script>
    function showUser(str)
    {
    alert(str + "hello");
    
    
    xmlhttp.open("GET","TryQ.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    Instead of launching "TryQ.php" the routine reverts to itself in an endless loop.

    Then, the code for TryQ.php:
    PHP Code:
    <?php
    $q
    =$_GET["q"];
    echo 
    'help ' $q;
    die();
    Yep, that's all there is for now. What am I doing wrong?

  7. #7
    Senior Member
    Join Date
    Sep 2012
    Posts
    269
    Google keeps drawing me to this code:
    Code:
    <script>
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","demo_get2.asp?fname=Henry&lname=Ford",true);
    xmlhttp.send();
    }
    </script>
    This works fine if triggered by a button, but I'll be switched if I can figure out how to pass a variable to the function with "onChange".

    Any more hints?

    I'll get that duck sooner or later.

  8. #8
    Senior Member
    Join Date
    Sep 2012
    Posts
    269
    Persistance. I now have enough feathers to make a king-size mattress. I'll probably have another question in a few minutes.

  9. #9
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    428
    Maybe instead of going for the full monty.... start with the basics. It will help in the long run. As far as onchange.... yourFunc(this.value);

    hth
    Bob Lob Law

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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