Jump to content

Get selected in <select>...?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
nick3

nick3

    Newbie

  • Members
  • PipPip
  • 29 posts
<form method="POST" action="">

          <label for="word">Choose:</label><?php

          echo "<select>";

          foreach($WC->wordArray as $word)         

                echo "<option>".$word->get_word()."</option>";

          echo "</select>";?>

          <input type="submit" value="Send" name="Send" />

          </form>

My current code look like this... (to create my drop down box) but how could I check what one is selected? (I want to preform an action on the selected object) I get that I may only get the index, but thats fine, could work with that.

#2
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
If you set a value in the '<option>' tag, you can reference that.

Like:
echo "<option value="yourvalhere">".$word->get_word()."</option>";

Then it will post that value. If you want to make it index like, you can set the values to 1, 2, 3 etc. :)

#3
nick3

nick3

    Newbie

  • Members
  • PipPip
  • 29 posts
But then can I make like a dynamic isset() or something? becouse I dont know how many items will be in the drop down box...

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you can have your word as value as well...

echo "<option value=\"".$word->get_word()."\">".$word->get_word()."</option>";  

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
nick3

nick3

    Newbie

  • Members
  • PipPip
  • 29 posts

Orjan said:

you can have your word as value as well...

echo "<option value=\"".$word->get_word()."\">".$word->get_word()."</option>";  

yeah ok, but I guess I need to do something like...

foreach(word$ as $w){
       if(isset($_POST[$w->get_word]))
               $w->do_something();
}

But I wont get that to work... maybe you cant do that? what could you do instead in that case?

#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
You never named your select element. Name it, then you can reference it.