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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get database value to text field+click button

    Hello,

    I have a problem in getting database query result to text field when button was clicked. So far I have two php files, one used to connect database and save the database query value to a variable. The second php file used to create the buttons and text field.
    code for dbconnection.php
    [code]
    $con_str = "host=jojo1234 port=3214 dbname=postgres user=postgres password=postgres";
    $con = pg_connect("$con_str") or die('Could not connect: ' . pg_last_error());
    $queryresult1 = pg_query($query1);
    $result11=array_sum(pg_fetch_array($queryresult1));
    [code]
    code for interface.php
    [code]
    <html>
    <head> jsadfj</head>
    <body>
    <form name = "weightform" action = "dbconnect.php" method = "post" target="hidden">

    <input type="submit" name="submit" value = ""/>
    <input id='wb1' type="text" name="wb1" value=""/>
    </form>
    </body>
    </html>
    [code]
    my problem is how to get ´$result11 vlaue to text field wb1 when button submit was clicked. By using form, these two php files can hear each other. but I don´t know how to get first php file variable value. I have been thinking about the solution. one solution is to create funtion called getTxtField(), here is psudo code
    [code]
    getTxtField(){
    connect to database
    wb1.value=$result11
    }
    <input type="submit" name="submit" value = onclick"getTxtField()" />
    [code]
    but I don´t know if this [ICODE]wb1.value=$result11[ICODE] can be done. what could be the right syntax.

    This is my first time program with javascript. some javascript syntax still new for me. Does anyone can help me to get sample code which could help me with this problem.Or do you have some better idea to solve this problem.

    Thanks a lot.

  • #2
    New Coder
    Join Date
    Aug 2010
    Location
    FL
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post
    Jojo, this is a job for AJAX (Asynchronous Javascript and XML). Please look into using AJAX to populate forms.


  •  

    Posting Permissions

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