...

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



jojo1234
08-31-2010, 11:57 AM
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.

codebyter
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum