tomks77 Posted May 29, 2013 Share Posted May 29, 2013 we can add dropdown menu in the html part like this: <select name"select1"><option>One</option></select> Ok, something like that, and we use the name "select1" in the php part like this:$_POST['select1']; but i found that i can not use the dropdown menu in the php part when i add it through the php.like this: <?phpprint "<select name='select1'>";print "<option>";print "One";print "</option>";print "</select>";?> because when i try to check what option the user chose using:$_POST['select1']i receive the error : undefined variable select1. if any one have an idea or a website that talk about this i'll be glad..I found some sites but itall use javascript to define what option the user click on.. is this mean there is no way to handle this issue using php?? Link to comment Share on other sites More sharing options...
MarkT Posted May 29, 2013 Share Posted May 29, 2013 (edited) is this mean there is no way to handle this issue using php?? I don't really get what you're saying, but i assume;<select name="drop"> <option value="1">One</option><option value="2">Two</option></select> Then On your HTML Form Action document.For this demo; bob.phpcontents: $option = $_POST['drop'] Then echo '{$option}' Edited May 29, 2013 by MarkT Link to comment Share on other sites More sharing options...
justsomeguy Posted May 29, 2013 Share Posted May 29, 2013 It doesn't matter whether PHP generates the HTML code or you type it by hand or whatever else, the browser doesn't care about that. It will work if the HTML is formed properly. Among other things, that means the select element needs to be inside a form element. echo '{$option}' That's going to print the text "{$option}". There's no reason to wrap it in quotes: echo $option; Link to comment Share on other sites More sharing options...
MarkT Posted May 29, 2013 Share Posted May 29, 2013 It doesn't matter whether PHP generates the HTML code or you type it by hand or whatever else, the browser doesn't care about that. It will work if the HTML is formed properly. Among other things, that means the select element needs to be inside a form element. echo '{$option}' That's going to print the text "{$option}". There's no reason to wrap it in quotes: echo $option;I got most of it right Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now