Trojan Trojan - 5 months ago 14
PHP Question

Undefined error when i try to put a disabled="disabled"

I have a select option and put

disabled="disabled"
so that it cannot be selected, but when I try to press the update button it always give me this error.


error Notice: Undefined index: Province in
D:\wamp\www\LTID\Updaterlbet.php on line 35


But when i try to remove the
disabled="disabled"
it update successfully. But, i want that disabled to be put there so it cannot be selected..

The code

$Province = isset($_GET['fruit']) ? $_GET['fruit'] : '';

if(isset($_POST['update'])){
$ID = $_GET['ID'];
$fruit = $_POST['fruit'];
}


HTML

<select name="Province" class="form-control" id="category" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
<option selected="selected" value="<?php echo $fruut; ?>" disabled="disabled"><?php echo $fruit; ?></option>
<option value="strawberry">strawberry</option>
<option value="raspberry">raspberry</option>
<option value="blueberry">blueberry</option>
</select>

Answer

it will always throws an error because the disabled option is always selected base on your code. To get the fix, remove the selected attribute.

Remove: selected="selected"

Now it will look like this

<select name="Province" class="form-control" id="category" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
       <option value="<?php echo $Province; ?>" disabled="disabled"><?php echo $Province; ?></option>
       <option value="ALBAY">Albay</option>
       <option value="CAMARINES NORTE">Camarines Norte</option>
       <option value="CAMARINES SUR I">blu</option>
</select>

Or use this piece of code if you want to select the disabled value as default.

<option selected="true" disabled="disabled" <?php echo $Province; ?>><?php echo $Province; ?></option> 
Comments