Javascript & PHP
Discussion
Right, I have a select list that I want to use to set a PHP variable..... But for reasons best known to myself, I don't want to submit the form.
I was going to use the "onchange" property to populate my variable, but I just can't get it to work.
I would have thought the following would do it, but it doesn't (I have omitted bracketing to get it to post!!).
Any javascript experts know how I can populate my variable when the select list is selected? It's doing my box in
I was going to use the "onchange" property to populate my variable, but I just can't get it to work.
I would have thought the following would do it, but it doesn't (I have omitted bracketing to get it to post!!).
My Code said:
select name="search" width = "50" onChange=" ?php $widget; = document.searchform.search.value"
Any javascript experts know how I can populate my variable when the select list is selected? It's doing my box in

I'm open to any suggestions!!!
All I want to do is use what's in my dynamic select list to set a session variable on the page it ends up on. However, because I am not submitting the form, I can't use a $_POST
I can make the form submit itself easy enough with something like
onchange="searchform.submit();"
whenever what's in the list changes and it works... But then the list doesn't reflect what's actually been chosen.
All I want to do is use what's in my dynamic select list to set a session variable on the page it ends up on. However, because I am not submitting the form, I can't use a $_POST
I can make the form submit itself easy enough with something like
onchange="searchform.submit();"
whenever what's in the list changes and it works... But then the list doesn't reflect what's actually been chosen.
BliarOut said:
I'm open to any suggestions!!!
All I want to do is use what's in my dynamic select list to set a session variable on the page it ends up on. However, because I am not submitting the form, I can't use a $_POST![]()
Naturally... let me see if I have this straight: you want to choose a variable from a list and make that variable know to whatever page is next loaded without actually submitting anything back to the server? If that is the case, you'll have to do some javascript fiddling - IMHO not a good idea.
BliarOut said:
I can make the form submit itself easy enough with something like
onchange="searchform.submit();"
Javascript-submitted forms are the devil's own work... ;-)
BliarOut said:
whenever what's in the list changes and it works... But then the list doesn't reflect what's actually been chosen.
Yes, you'd need to filter it out server-side, and add the appropriate html tag (either <option... ... selected> or Moption ... ... selected="selected"> depending on your html flavour) in the form elements.
Is there a url where I can take a look at this for you?
Ciao
Zak
BliarOut said:
Sod it, I'll submit the form ![]()
All I need to do is make my buttons graphical and lay them out and it'll still work. I just like to save a click wherever possible
You won't will save a click, since when the select list is changed, the page will submit automatically (bit of JS), PHP can then process the contents of the $_POST collection and re-display the form again complete with original data + the changes made.
Sadly, there is no way round this without submit. The classic example is where you have combo boxes or lists that are dynamically populated from other lists, eg a combo box of Car Makes, once selected populates the Car Model list.
However, I've thought, there is a way, but it's messy. It basically involves populating JS arrays from the PHP code and using JS onClick or onChange functions to populate the lists from the arrays...
Oh, fun, fun, fun...
Steve
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


