1

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>
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
Trojan
  • 91
  • 2
  • 12

2 Answers2

2

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> 
claudios
  • 6,588
  • 8
  • 47
  • 90
  • i have try your code and it works but the problem now is that its not showing the current record..like for example..the current record is disabled and if i updated it it is successfull but it shows me the next on the which is ALBAY. – Trojan Jun 20 '16 at 02:17
  • do you want the disabled option to be the default selected value? is that what you mean? – claudios Jun 20 '16 at 02:28
  • It always select what you have selected of course. disabled value will not be selected that's why it's disabled. – claudios Jun 20 '16 at 02:29
  • yes..i want the disabled to be my default value – Trojan Jun 20 '16 at 02:33
  • @Trojan, check my updated answer – claudios Jun 20 '16 at 02:38
  • Glad could help :) you may also vote it up :) – claudios Jun 20 '16 at 02:49
  • i have try your code for several times, it works on the first 10 tries but after that the problem still occur..what happened? – Trojan Jun 20 '16 at 04:08
1

You have selected="selected" in your code. Remove that and it should work just fine.

gotnull
  • 26,454
  • 22
  • 137
  • 203