Surkaav S
Surkaav S

Reputation: 49

Unexpected blank option in middle of select box

I am having a select option box which has four values pass, fail, hold and re-open. There is an unexpected blank option between fail and hold and I don't know why. Initially when I had only two options, I had this blank option.But now, when I have added other options this is in between and I want to remove it.

Here's the code:

<?php
echo"<td><select  id='res[]' name='res[]' form='test'>";
echo"<option disabled selected value>--Result--</option>";
echo"<option value='Pass'>PASS</option>";
echo"<option value='Fail'>FAIL<option>";                     
echo"<option value='Hold'>HOLD</option>";
echo"<option value='Reopen'>RE-OPEN</option>";
echo"</select>";
echo "</td>"; 

?>

I am echoing this because this is to be done after a query. This is in a table and is present in all rows of it. The current window:

This is the select option currently: I dont want the blank option to appear! Any help would be appreciated! Thanks in advance!

Note that this is inside a form and the values are posted to php

Edit: It's a typo by me! Got the solution. Forgot to close FAIL

Upvotes: 1

Views: 279

Answers (3)

Nawaz Ghori
Nawaz Ghori

Reputation: 591

you forgot to close the option tag properly. change your code to this

 echo"<td><select  id='res[]' name='res[]' form='test'>";
 echo"<option disabled selected value>--Result--</option>";
 echo"<option value='Pass'>PASS</option>";
 echo"<option value='Fail'>FAIL</option>";                     
 echo"<option value='Hold'>HOLD</option>";
 echo"<option value='Reopen'>RE-OPEN</option>";
 echo"</select>";
 echo"</td>";      

HTML Elements:

An HTML element usually consists of a start tag and end tag, with the content inserted in between:

<tagname>Content goes here...</tagname>

The HTML element is everything from the start tag to the end tag.

Ex: <p>My first paragraph.</p>

HTML elements with no content are called empty elements. Empty elements do not have an end tag, such as the <br> element (which indicates a line break). These are called self-closing tags. If we don't close this kind of tags, HTML closes it automatically

The other type of Explicit Closing tag which expects the closing tag.Some HTML elements will display correctly, even if you forget the end tag:

<p>This is a paragraph
<p>This is a paragraph

Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.

Upvotes: 2

Pupil
Pupil

Reputation: 23948

Change:

echo"<option value='Fail'>FAIL<option>";

To

echo "<option value='Fail'>FAIL</option>";

You forgot to close the option tag, it is creating a new one.

HTML is assuming that previous option tag is not closed and closes it automatically and creating a new blank option tag.

in HTML, there are two kinds of tags depending upon their closing.

Self closing tags:

<input/>

eg. <input type="text" name="age"/>

If we do not close this tag, HTML will close it automatically.

Explicit closing tag:

e.g.

<textarea name="notes"></textarea>

The <option> tag is of this type.

And it expects/assumes the closing tag.

Upvotes: 2

Parth Shah
Parth Shah

Reputation: 411

Here is the mistake in your html

echo"<option value='Fail'>FAIL<option>"; 

it should be like this

 echo"<option value='Fail'>FAIL</option>"; 

Upvotes: 2

Related Questions