Welcome to Dream.In.Code
Become an Expert!

Join 149,491 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,288 people online right now. Registration is fast and FREE... Join Now!




database query using html select option

 
Reply to this topicStart new topic

database query using html select option, postgresql query from html

rpjd
9 Mar, 2007 - 03:54 PM
Post #1

D.I.C Head
**

Joined: 8 Mar, 2007
Posts: 85


My Contributions
I need to query a postgresql database using a value selected from an html select form.
I cannot find any site which discusses this
I am using the following code to capture the forms selected value

document.form.partname.option.selected

the select form name is partname.

Not sure if I am using the correct syntax.

RPJD smile.gif





User is offlineProfile CardPM
+Quote Post

snoj
RE: Database Query Using Html Select Option
9 Mar, 2007 - 04:36 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
For starters, you can't query a database with HTML.

As for the javascript, you need to specify which form you wish to use from the page. (If there is only one form then document.forms[0].)

You may want to take a look at the documentation for the Mozilla DOM as it is very helpful and in many regards it's the same as what IE uses.
User is offlineProfile CardPM
+Quote Post

rpjd
RE: Database Query Using Html Select Option
11 Mar, 2007 - 07:27 AM
Post #3

D.I.C Head
**

Joined: 8 Mar, 2007
Posts: 85


My Contributions
QUOTE(rpjd @ 9 Mar, 2007 - 04:54 PM) *

I need to query a postgresql database using a value selected from an html select form.
I cannot find any site which discusses this
I am using the following code to capture the forms selected value

document.form.partname.option.selected

the select form name is partname.

Not sure if I am using the correct syntax.

RPJD smile.gif


My apologies, what meant to say, should have said was I am (hopefully) connecting to a Postgresql database using php embedded in a html file, using a selected form value as the basis of a select statements so
</php $a = pg_connect("select x from tablename where y = 'document.form.formname.option.selected';")
I am then trying to assign the value $a to a text field within the same form.
although document.forms[0] does looks much tidier I must admit!

When I assign the value to a text field say
<input name="x" value="<? php echo$a; ?>">
the php code is visible in the text field smile.gif

RPJD




User is offlineProfile CardPM
+Quote Post

snoj
RE: Database Query Using Html Select Option
11 Mar, 2007 - 09:05 AM
Post #4

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
That won't work because you're using Javascript within PHP. You'll need to send a new query/request to the server using some AJAXy type stuff or just have the whole thing reloaded when an option is selected.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 05:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month