Jump to content

Recommended Posts

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

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 by NotSunfighter
  • Great Answer 1

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 by Barand
  • Thanks 1
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.

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.

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.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.