SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help in getting values of two textboxes using jquery

    Hi,

    I am new in using JQuery, so now I only know is getting the value of one textbox. But now I need to get the value of the first textbox which is the process id. So that on my query on getting the machine I could also base on what process.

    here is my code:

    PHP Code:
    <?php
      error_reporting
    (0);
     
    session_start();
      
    ob_start();
      
    date_default_timezone_set("Asia/Singapore");
      
      include(
    'connection.php');
      
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <title>Operator's Shift Report </title>
    <head>

    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />

    <script type="text/javascript">

    //----auto complete process name---//

    $().ready(function() {
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        });  
         
    });

    //------auto complete machine 1---//
    $().ready(function() {
        $("#machine_1").autocomplete("get_machine_1.php", {
            width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
         $("#machine_1").result(function(event, data, formatted) {
            $("#ma_1").val(data[1]);
        });
    });

    </script>
    </head>
    <body>
    <form name="operator_report" action="<?php echo $PHP_SELF?>" method="post" autocomplete="off">
        <!--Tab List -->
    </div>
    <div id="operators_report">
    <fieldset>
    <legend><h1>Operator's Shift Report</h1></legend>

    <table>
    <td>Process:</td>
    <td><input type="text" name="process_name" id="process_name" value="" size="30" ></td>
    <td>Machine 1: </td>
    <td><input type="text" name="machine_1" id="machine_1" value="" size="30"></td>
    </tr>

    </table>

    </fieldset>
    </div>
    <input type="text" name="process_id" id="process_id" value="" />
    <input type="text" name="ma_1" id="ma_1" value="" />
    <div id="op_output_fieldset">

    </div>
    </form>
    </body>
    </html>
    here is my code in getting the machine name
    //---in this code I just want to get the process_id, but I have no idea what jquery code should I need to use to get the value of process_id.
    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";
    $q strtolower($_GET["q"]);
    //if (!$q) return;
    if ($q == '') {
       
    header("HTTP/1.0 404 Not Found"true404);   
    }
    else
    {
    $sql "select machine_id, machine_name from machine_list where machine_name LIKE '$q%'";
    $rsd mysql_query($sql);
    $cnt mysql_num_rows($rsd);

        if(
    $cnt 0)
        {
            while(
    $rs mysql_fetch_array($rsd)) {
                
    $sid $rs['machine_id'];
                
    $sname $rs['machine_name'];
                echo 
    "$sname|$sid\n";
            }
        }
        else
        {
            
    header("HTTP/1.0 404 Not Found"true404);    
        }   
    }
    ?>
    Thank you

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    But now I need to get the value of the first textbox which is the process id. So that on my query on getting the machine I could also base on what process.
    Whenever the process id is changed, you'll want to update the machine_1 autocomplete. You can do that by updating the source information on its autocomplete so that it includes the processid information.

    Code javascript:
    $("#process_name").result(function(event, data, formatted) {
        var processId = data[1],
            querystring = '';
     
        $("#process_id").val(processId);
     
        if (processId) {
            querystring = '?processid=' + encodeURIComponent($("#process_id").val());
        }
        $("#machine_1").autocomplete('option', 'source', 'get_machine_1.php' + querystring);

    That should update the autocomplete query to get_machine_1.php so that a request is made to get_machine_1.php?processid=12345&term=abc
    so that it has a processid key, as well as the usual term key.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where should I put that code?
    and how can i call or get the process id on my get_machine_1.php?
    Thank you

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    Where should I put that code?
    You can use it to replace this part:

    Code:
    $("#process_name").result(function(event, data, formatted) {
        $("#process_id").val(data[1]);
    });
    Quote Originally Posted by newphpcoder View Post
    and how can i call or get the process id on my get_machine_1.php?
    I suspect that filter_input will be a good way to get that info, but that's a question for which the PHP forum will be best able to answer.
    I'll move this thread over to the PHP forum so that they can weigh in on this.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you... I will try it

  6. #6
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    I tried this code:

    Code:
    //----auto complete process name---//
    
    $().ready(function() {
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        });  
        
        $("#process_name").result(function(event, data, formatted) {
        $("#machine_id").val(data[2]);
        });      
        
        $("#process_name").result(function(event, data, formatted) {
        $("#machine_1").val(data[3]);
        });  
        
        $("#process_name").result(function(event, data, formatted) {
        $("#machine_2").val(data[3]);
        });  
    });
    and the php code:

    PHP Code:
    $sql "select p.process_id, p.process_name, m.machine_id, m.machine_name 
    from process_list AS p JOIN machine_list AS m ON (p.process_id = m.machine_process_id) 
    where process_name LIKE '%
    $q%'";
    $rsd mysql_query($sql);

    $cnt mysql_num_rows($rsd);

        if(
    $cnt 0)
        {
            while(
    $rs mysql_fetch_array($rsd)) {
                
    $pid $rs['process_id'];
                
    $pname $rs['process_name'];
                
    $mid $rs['machine_id'];
                
    $mname $rs['machine_name'];
                echo 
    "$pname|$pid|$mid|$mname\n";
            }
            } 
    when I choose process name it automatically displayed the first machine name on the machine_1 textbox and on the machine_2 textbox.
    but i want to happen is it only displayed all the machine list on the machine_1 when I start type on the machine_1 textbox which is connected the value to process_id. Is it possible?


    Thank you

  7. #7
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or in this code:

    Code:
    $().ready(function() {
        $("#machine_1").autocomplete("get_machine_1.php", {
            width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
         $("#machine_1").result(function(event, data, formatted) {
            $("#ma_1").val(data[1]);
        });
    });
    how can i get also the process_id?

    so that I can get on my php file:

    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";
    //--like this
    $process_id $_GET['process_id'];
    $q strtolower($_GET["q"]);
    //if (!$q) return;
    if ($q == '') {
       
    header("HTTP/1.0 404 Not Found"true404);   
    }
    else
    {
    $sql "select machine_id, machine_name from machine_list where machine_name LIKE '$q%'";
    $rsd mysql_query($sql);
    $cnt mysql_num_rows($rsd);

        if(
    $cnt 0)
        {
            while(
    $rs mysql_fetch_array($rsd)) {
                
    $sid $rs['machine_id'];
                
    $sname $rs['machine_name'];
                echo 
    "$sname|$sid\n";
            }
        }
        else
        {
            
    header("HTTP/1.0 404 Not Found"true404);    
        }   
    }
    ?>

    Thank you


Bookmarks

Posting Permissions

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