/    Sign up×
Community /Pin to ProfileBookmark

php and javascript

Hello all,

I am facing a problem with php and javascript , i donot know if this is the right forum to post..

my problem is i want to do a search filter contains multiple dropdown menus
when the user select an item from the first menu the second menu start viewing its contents depending on the user selection with an sql query to retrieve data from data base.
I got the selected value with javascript function but now i want to pass it to a php variable to help in database search ..

i searched with google all what i found is to pass the js value through a query string but i donot want to do that i need all these done in the same page without loading….

i thought about ajax but i couldnot get a clear solution …

any suggesstions?

Thank you.?

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiOct 08.2007 — So you're saying that you want a sub-menu of a sub-menu to be the result of an sql query?

Why don't you simply load the result of the sql query in a javascript variable(s) when the user loads the page? Instead of doing it the other (and harder) way...

If you really want to execute the query when the user tries to access the menu, you should look into Ajax (here's [URL=http://www.w3schools.com/ajax]a pretty good tutorial[/URL]), but if the user has a slow connection or if your server is overloaded, beware that the user might have to wait a while with their mouse hovering on the first sub-menu until they get the next one, which would be pretty unpleasant.
Copy linkTweet thisAlerts:
@lizaauthorOct 08.2007 — 
Why don't you simply load the result of the sql query in a javascript variable(s) when the user loads the page? Instead of doing it the other (and harder) way...

[/QUOTE]


sorry how can i run sql query inside the java script function i did not do that before.. the query written in php and i have a where statement depends on the selected value from the first menu????
Copy linkTweet thisAlerts:
@WebnerdOct 08.2007 — It sounds like you need to add an :

<select onchange="document.forms['yourform'].submit()">

To your<select> boxes so when the user changes the value, the form submits.

Your PHP code needs to do the SQL query creation though
Copy linkTweet thisAlerts:
@ZnupiOct 08.2007 — Oh by dropdown you meant a <select> object? Sorry, I was tired and understood dropdown menus (for navigation and sorts). In that case you can use Webnerd's solution or Ajax ?
Copy linkTweet thisAlerts:
@lizaauthorOct 08.2007 — what is Webnerd's solution ??

i know it can be solved by ajax but as i said in my first post that i donot have any idea how can i do that??

i did not use ajax before???

sorry for my questions
Copy linkTweet thisAlerts:
@WebnerdOct 08.2007 — liza, do you do PHP programming? Do you have access to the PHP page? If not, you will not be able to accomplish what you want easiliy.
Copy linkTweet thisAlerts:
@WebnerdOct 08.2007 — liza, it actually sounds like you are way out of your league to provide the programming for what you want to do. I'm sure that there are plenty of programmers out there that would glad to be paid to provide you with your solution ?
Copy linkTweet thisAlerts:
@lizaauthorOct 08.2007 — yes i have an access to php

Iam just new to php
Copy linkTweet thisAlerts:
@ZnupiOct 08.2007 — Webnerd's solution:

It sounds like you need to add an :

<select onchange="document.forms['yourform'].submit()">

To your<select> boxes so when the user changes the value, the form submits.

Your PHP code needs to do the SQL query creation though[/QUOTE]


Also, in my first post I posted a link to an Ajax tutorial....
Copy linkTweet thisAlerts:
@lizaauthorOct 08.2007 — Iam so sorry for all of you for my silly questions

i will try both of ur solution

thank you soo much for this great help
×

Success!

Help @liza spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...