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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post

    pass textbox value to php without submitting form

    Good day all:

    I want to get the value of a textbox into php without clicking the submit button. Any advice... Here is what I have
    My form field:

    Code:
    #1
    <input type="text" style=background:transparent; border:0px; name='clientid' >
    This field is populated dynamically by its name with another php script in this way
    Code:
    #2
        echo "formObj.clientid.value = '".toSafeString($inf["clientID"])."';\n";
    Now I want to take the value in code#1 (name='clientid') and pass it to a php code that is in the same file as the form. Here is the php code
    PHP Code:
    <?php
     $name
    =$_POST['name'];//this is where the value of the text box mentioned is defined
    include 'datalogin.php';

    error_reporting(0);
    error_reporting(E_ERROR E_WARNING E_PARSE);
    //test
    //get image details 
    $uploaddir "images/clientsimages/";

    $get_data "SELECT i.uploadedfile, i.clientid " " FROM images AS i, ajax_client AS a " " WHERE i.clientid = a.clientID " " AND a.clientID = $name";

    $get_data_res mysql_query($get_data) or die(mysql_error() . '<br>sql : '.$get_data); 

    if (
    mysql_num_rows($get_data_res) > 0

        while (
    $get_data_info mysql_fetch_array($get_data_res)) 
        { 
            
    $uploadedfile $uploaddir $get_data_info["uploadedfile"]; 

            
        }
    }

    ?>
    I know this may require js, but I appreciate any help!
    Last edited by mbarandao; 12-21-2010 at 04:38 PM.

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Search Google for AJAX examples as you will need AJAX to allow Javascript and PHP to communicate and do the job you want it to do.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    Thanks for the reply. I'm not using js currently. My question is whether I can use js to be able to get the textbox input value from the form to php code?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    And you got the answer. AJAX. Period. There's no other way.

    You might start here:
    http://www.w3schools.com/php/default.asp

    Look down the page to the category "PHP and AJAX".

    Be prepared to start learning JavaScript.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    Thank you! looking into it now...


  •  

    Posting Permissions

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