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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts

    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);    
        }   
    }
    ?>

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    $("#process_id").val(); will get the value of the process_id input. Im not sure why you find this confusing as you are already doign so in your code......

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    $("#process_id").val(); will get the value of the process_id input. Im not sure why you find this confusing as you are already doign so in your code......
    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

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ok, so

    Code:
        $("#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]);
        });

    is the same as


    Code:
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        $("#machine_id").val(data[2]);
        $("#machine_1").val(data[3]);
        $("#machine_2").val(data[3]);
        });

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    for the first piece of data ( the id), shouldnt you be using data[0]?
    Last edited by DanInMa; 07-24-2013 at 04:28 PM.

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    ok, so

    Code:
        $("#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]);
        });

    is the same as


    Code:
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        $("#machine_id").val(data[2]);
        $("#machine_1").val(data[3]);
        $("#machine_2").val(data[3]);
        });
    Hi,

    In that code it automacally displayed the machine name, but I want is only on autosuggset it will display after typing the first letter.

    Thank you


  •  

    Posting Permissions

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