View Full Version : get database value to text field+click button

08-31-2010, 11:57 AM

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
$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);
code for interface.php
<head> jsadfj</head>
<form name = "weightform" action = "dbconnect.php" method = "post" target="hidden">

<input type="submit" name="submit" value = ""/>
<input id='wb1' type="text" name="wb1" value=""/>
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
connect to database
<input type="submit" name="submit" value = onclick"getTxtField()" />
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.

08-31-2010, 07:50 PM
Jojo, this is a job for AJAX (Asynchronous Javascript and XML). Please look into using AJAX to populate forms.