select list-drop down menu and php

select list-drop down menu and php

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

i got this problem with my script.
here is the code

........ <select name="menu">                 <option value="" selected>Select</option>                    <option value="one">one</option>                    <option value="two">two</option>                    <option value="three">three</option>   </select> <?php Here should be the php code for executing the select

so i when i choose "two" from the menu, i want to go to "two.php".
Any help?


i try this with a submit button but also is not working
........ <select name="menu">                 <option value="" selected>Select</option>                    <option value="one">one</option>                    <option value="two">two</option>                    <option value="three">three</option>   </select> <input type="submit" name="submit" value="submit"> <?php if ($_POST['submit']) {        if ($_POST['menu'] == 'one')        { header "Location:one.php" }        if ($_POST['menu'] == 'two')        { header "Location:two.php" }           if ($_POST['menu'] == 'three')           { header "Location:three.php" } } else{} .......

is this code ok?



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

Use a <form> tags



offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

lol man, i wrote dots ... that's mean that before the dots there is html script, just like html, body, form etc etc

offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

ok, is problem with header?

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

maybe, that i m asking Smile

here is a "visible example"

in the site for php section "http://www.mycity.rs/PHP/" u have on the right a drop down menu..... i think u will find it Smile

offline
  • Pridružio: 11 Maj 2005
  • Poruke: 871
  • Gde živiš: Aleksinac - Niš

You should try using Javascript.
Make a function that will be executed onSubmit.
In that function you check which option is selected.
Something like:
... function setAction() { if(form1.menu.value=="one") {     form1.action="one.php";     form1.submit(); } ... }
I haven't worked in Javascript for quite a long time so I don't know how accurate this code is but I'm sure it can be done this way.

offline
  • PHP developer
  • Pridružio: 22 Mar 2006
  • Poruke: 3664
  • Gde živiš: 127.0.0.1

I use this for redirecting via SELECT box Smile

HTML:

<select name="menu" onchange="RedirectMe(this.value);"> <option value="empty" selected>Select</option> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select>

and JavaScript:

function RedirectMe(page) { var page; if (page != "empty"){ location.href = page+'.php'; } }

offline
  • Pridružio: 30 Sep 2006
  • Poruke: 137

i will try that.

tnx guys

Ko je trenutno na forumu
 

Ukupno su 683 korisnika na forumu :: 40 registrovanih, 3 sakrivenih i 640 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 39mm, _Rade, A.R.Chafee.Jr., Aleksandar Tomić, amaterSRB, amstel2, Apok, Atomski čoban, awathorn, Belac91, cenejac111, dankisha, dolinalima, Dorcolac, dragon986, dule10savic, Georgius, HrcAk47, kolateralnasteta, Leonardo, lukac, mercedesamg, Mercury, miljannis, miodrag, nenad81, pein, pjaka2001, rovac, sabros, sakota79, sevenino, Snorks, Srki98, Srky Boy, Toni, trajkoni018, VaRvArI 85, Vatreni Zmaj, virked