0

I need when user not select any database value option tag print error color in to parent div. I used that code for <input type="text"> html tag code to print text field pattern not matching time printing error. code is below

<label class="col-md-3 control-label">Product Title</label>
    <div class="col-md-6">
        <input type="text" name="product_title" class="form-control" required 
placeholder="Product Name" value="" pattern="([A-z0-9À-ž\s]){2,}" 
oninvalid="setCustomValidity('Please enter least two characters long name')"
onblur="this.parentNode.parentNode.style.backgroundColor=/^([A-z0-9À-ž\s]){2,}/.test
(this.value)?'inherit':'orange'" >
    </div>

That is done for me onblur event. image of working print error Then now i want print error color when user not select any database value option in <select></select>tag. this is the default value i given. <option>Select a Manufacturer</option> I need print error when user select this or forget select database values in that <option> tag.

This is the code section

<div class="form-group"> <!-- form-group Start -->
 <label class="col-md-3 control-label"> Select a Manufacturer </label>
    <div class="col-md-6">
    <select class="form-control" name="manufacturer" required="required">
        <option>Select a Manufacturer</option>
            <?php 

            $get_manufacturer ="select * from manufactures";
            $run_manufacturer = mysqli_query($con, $get_manufacturer);
                while($row_manufacturer = mysqli_fetch_array($run_manufacturer)){
    $manufacturer_id = $row_manufacturer['manufacturer_id'];
    $manufacturer_title = $row_manufacturer['manufacturer_title'];

echo "<option value='$manufacturer_id'>$manufacturer_title</option>";
        }
        ?>
        </select>
</div>

How can i do this?

ahmednawazbutt
  • 823
  • 12
  • 34
Sahan Pasindu Nirmal
  • 433
  • 4
  • 13
  • 36

2 Answers2

0

Just do<option value="">Select a Manufacturer</option>.

Please see next link for reference: https://www.w3schools.com/tags/att_select_required.asp

Vitalii Chmovzh
  • 2,825
  • 4
  • 14
  • 28
0

I use J-Query here my code

<select class="form-control" name="manufacturer" required="required" onchange="getval(this);">
  <option value="0">Select a Manufacturer</option>

Then i used this script to change background

<script type="text/javascript">
    function getval(sel)
    {
        if(sel.value == "0"){
            $("#sel").css("background-color", "orange");
        }
    }
</script>

Finally i fixed it fixed code output

Sahan Pasindu Nirmal
  • 433
  • 4
  • 13
  • 36