简体   繁体   中英

Select problems in IE9 - in other browsers it works perfectly

I have problems with this particular form, i need first to select a value and then to submit the form. Submit form works good, however the default selection value in all browsers is selected and it is Acceptable, except in IE where no default selection value is selected. In IE there is nothing selected by default.

How do I fix this?

Picture of the problem : 选择表格

:

  <select name="formQuality" id="formQuality" value="acceptable"> <option value="acceptable">Acceptable</option> <option value="good">Good</option> <option value="better">Better</option> <option value="excellent">Excellent</option> <option value="best">Best</option> </select> 

 <?php if(isset($_POST['SubmitButton'])){ //check if form was submitted $input = $_POST['inputText']; //get input text $varQuality = $_POST['formQuality']; $message = "Success! You entered: ".$input; } ?> <br> <form action="" method="post"> <h1>Choose Quality:</h1> <?php $thequa = htmlspecialchars($_POST['formQuality']); ?> <select name="formQuality" id="formQuality" value="<?php echo $thequa;?>"> <option <?php if ($thequa1 == 'acceptable') { ?>selected="true" <?php }; ?> value="acceptable">Acceptable</option> <option selected="true" value="acceptable">Acceptable</option> <option <?php if ($_POST['formQuality'] == 'good') { ?>selected="true" <?php }; ?> value="good">Good</option> <option <?php if ($_POST['formQuality'] == 'better') { ?>selected="true" <?php }; ?> value="better">Better</option> <option <?php if ($_POST['formQuality'] == 'excelent') { ?>selected="true" <?php }; ?> value="excellent">Excellent</option> <option <?php if ($_POST['formQuality'] == 'best') { ?>selected="true" <?php }; ?> value="best">Best</option> </select> <textarea name="inputText" cols="100" rows="20" style="border:solid 1px orange;"><?php echo $thetext;?></textarea> <p> <input type="submit" value="Rewrite" name="SubmitButton"/> </form> 

The intended way to preselect an option is setting the selected attribute on the option element, rather than adding a value attribute to the select field.

 <select name="formQuality" id="formQuality"> <option value="acceptable" selected>Acceptable</option> <option value="good">Good</option> <option value="better">Better</option> <option value="excellent">Excellent</option> <option value="best">Best</option> </select> 

This produces the expected result in all browsers, including IE.

Use selected="selected" Like,

<option value="My Default" selected="selected">

to make an option as default selected value. This works in all browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM