2020 Posted July 12, 2020 Share Posted July 12, 2020 Folks, I remember once having a php or html5 issue where the first option had to be blank in the drop down. Otherwise, it wasn't working. What wasn't working ? How wasn't working ? I can't remember. either php had difficulty reading user input or the drop down was not showing any options. And so, I had to add a blank value. So, something like this wasn't working ... <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> And, I think I added a blank value, at somebody's advice, to get it to work. I think it was something like this, if I remember correctly: <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" ">Select here</option> <option value="yes">Yes</option> <option value="no">No</option> </select> Or, maybe it was something like this: <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" "></option> <option value="yes">Yes</option> <option value="no">No</option> </select> I can't remember. All I remember slightly that there was a blank value. I been going through my php files to find that particular file to jog my memory but I failed to find it. Can you folks explain to me if a blank value is required or not ? What is the benefit/disaster of adding it and how should the blank value be added ? Show me an example. Was this a php or html 5 issue ? Can anybody fugure ? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/ Share on other sites More sharing options...
NotSunfighter Posted July 12, 2020 Share Posted July 12, 2020 (edited) Either of the last two codes are OK, but I would use the first one and set the value of the first option to nil: <option value="">Select here</option> and not a space. Question: If this is a yes/no thing why not use simple Radio buttons Edited July 12, 2020 by NotSunfighter 1 Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/#findComment-1579567 Share on other sites More sharing options...
Barand Posted July 12, 2020 Share Posted July 12, 2020 (edited) It's neither a PHP thing nor a HTML5 thing - it's a plain, old HTML <select> thing. By default, if none of the options have their selected attribute set, the first option is shown as selected. Edited July 12, 2020 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/#findComment-1579571 Share on other sites More sharing options...
2020 Posted July 14, 2020 Author Share Posted July 14, 2020 On 7/12/2020 at 9:04 PM, NotSunfighter said: Either of the last two codes are OK, but I would use the first one and set the value of the first option to nil: <option value="">Select here</option> and not a space. Question: If this is a yes/no thing why not use simple Radio buttons I remember now! When my dropdown wasn't working, i was advised to add at the top of all options: <option value="">Select here</option> How come tutorials don;t teach this ? I gave 2 links, you can easily see they don't teach this. How did you programmers figure it out to do it like that to rid the problem, if tutorials didn't teach you ? Confused. Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/#findComment-1579614 Share on other sites More sharing options...
2020 Posted July 14, 2020 Author Share Posted July 14, 2020 On 7/12/2020 at 11:45 PM, Barand said: It's neither a PHP thing nor a HTML5 thing - it's a plain, old HTML <select> thing. By default, if none of the options have their selected attribute set, the first option is shown as selected. You mean, by default if the programmer doesn't set an option to select "selected>" then by default the first option gets selected ? Well, I didn't have any selected by default, no option had the "selected>" and still my dropdown didn't work. Can't remember how it malfunctioned. I think the drop down menu was not appearing to show any options until I added the snippet: <option value="">Select here</option> Then it worked. Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/#findComment-1579615 Share on other sites More sharing options...
cyberRobot Posted July 14, 2020 Share Posted July 14, 2020 46 minutes ago, 2020 said: You mean, by default if the programmer doesn't set an option to select "selected>" then by default the first option gets selected ? Yes 46 minutes ago, 2020 said: Well, I didn't have any selected by default, no option had the "selected>" and still my dropdown didn't work. Can't remember how it malfunctioned. I think the drop down menu was not appearing to show any options until I added the snippet If the drop down was malfunctioning, there was something else wrong with the code. Perhaps one of the tags was missing or coded incorrectly. All the above "Select here" code does is create a new option in the drop down so that neither "Yes" or "No" is the default selection, which is a good way to make sure the user actually makes a selection. They have to actually to interact with the drop down to answer the question. 1 hour ago, 2020 said: How come tutorials don;t teach this ? That depends on the tutorial. Most tutorials don't talk about everything a reader needs to know in order to do something. Otherwise too much time will be spent on trying to explain the basics before they can get to the topic the tutorial was designed for. Or maybe this was beyond the scope of the tutorial. If the tutorial was about creating a simple form, for example, they are not going to go into ever facet of an HTML form. There would be too many things to discuss for a single tutorial. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311075-was-this-a-php-issue-or-an-html5-drop-down-issue/#findComment-1579618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.