Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/JS select redirect/variable

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Ok, weird topic, but here's the lowdown:
I have a page with a pulldown box. ATM, it uses JS (javascript) and when an option is selected it goes off to a URL depending on the pulldown list's value.
But I've spent a while updating the stuff without rememebring PHP is serverside not clientside.
The problem is now this: all my pages check to see if a variable (eg $x) exists and if not make it equal something default (eg 1). They then call a stylesheet depending on what X is. Thus I have the same page using different styles depending on what the variable is as you can imagine. This works fine but the problem is I want the pulldown box to change the variable and then reload the pages (it's a frames layout) or to at least change the variable and goto a set (perhaps) url. But atm I don't see how I can change the PHP variable it checks at the start of every page when the pulldown box is changed. Please help! I'm sure there's just a way of thinking about it I've missed as usual. Thanks!!
 
you can always do a function in javascript that is activated onchange of the select. this function redirects the user to the new URL and you can even setup the X var.
<script language=javascript>
function changedselect(){
switch(document.myform.color.options[document.myform.color.selectedIndex].value){
document.url='newurl.php?color='+document.myform.color.options[document.myform.color.selectedIndex].text+'X='+color.options[document.myform.color.selectedIndex].value;
}
}
</script>

<form name=myform method=get>
<select name=color onchange=&quot;changedselect()&quot;>
<option value=1>Blue</option>
<option value=2>Red</option>
</select>
</form>

Well something like this. Read this and i hope you can solve your problem. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I have a function that goes to a URL that is comprised of what is the value of the selected index, eg my select box would have values like &quot;../abc&quot; or &quot;../abc/xyz.htm&quot; and it worked. But now I want to impliment this whole PHP thing, and every page checks for a variable and changes the style and title frame page depending on that variable. The question is how do I get the select box to change this variable in PHP somehow?
Thanks =) It's a fiddler ...
 
Anyone? I could do with thoughts if not a solution?
 
i don't understand. Explain better, please. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Okay. I have a pulldown menu on a page. At the moment the pulldown menu contains alues like &quot;../blah&quot; and when it is changed the javascript goes to that page, which contains it's own styled versions of all the pages on the site and it's own styled header.
However, enjoying PHP, or the ease of dabbling with it anyway, I wanted to bring PHP in and utilise the following structure instead.
Every page now checks a PHP veriable we'll call $style.
If it doens't exist the default is chosen. Then it loads a .css file for that style. This works, and meansI only need 1 copy of all the files, not a folder for each style. However. I need to figure out how to make the javascript, when the pulldown box changes, not goto a webpage, but to somehow refresh the current page, but before doing so, change the crucial PHP variable $style so that once refreshed the pages use this new style. But I don't see how to change PHP the variables using javascript or the pulldown menu =( Not even after reading up on $_get_vars n all that.
 
you only can change the PHP var in a new call to the server. You must do a refresh of the page or go to a new one to change it.

i don't know what you are trying to do, but i'll try to shoot a code example:
<form name=myform action=somewhere.php method=get>
<select name=myselect onchange=&quot;myform.action='<?=$PHP_SELF?>?xpto='+myform.myselect.options[myform.myselect.selectedIndex].value;myform.submit();&quot;>
<option value=&quot;../blah/&quot;>../blah</option>
</select>
...
</form>

Is this what you want?
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks that seems to be what I want, though I'll have to decypher the onChange part, ebcause I've no idea what 50% of it does, unless you break each part down for me =) Thanks though
 
what it does is simple as this,

When you change the option in the select, it does a refresh on that page passing the var xpto with the value of the selected option.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
What is this xpto value?
I built a dummy site for testing and using your code and modifying things till I figured it out I made a successfully ctyle and page changing layout which changed when the pulldown menu was changed. My selectbox is on a frame within the page that needs to be refreshed, so my code is refreshing the parent frame, or repointing it basically.
The onchange code looks like this:
<select size=&quot;1&quot; name=&quot;style&quot; onchange=&quot;parent.frames.location.href='index.php?style='+StyleForm.style.options[StyleForm.style.selectedIndex].value;StyleForm.submit();&quot;>
This means I goto &quot;index.php?style=style1&quot; or whatever.
Using this &quot;style=$style&quot; type thing I can pass it on to all pages. However - surely every link I goto doesn't have to be appended with it? Surely there is a way that the selectbox can enter it's choice into a session variable or something so every link on the site can pick up the same value for that variable and every page itself doesn't need it to be sent to it eg &quot;muppet.php?style=style1&quot;?
Thanks for any more help providable.
 
yes you can, but sessions are run in the server, so you must pass the new value to the refresh of the page.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top