dongyu1918 2015-09-28 12:39
浏览 28

在IE9中选择问题 - 在其他浏览器中它完美运行

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 : the selection form

:

  <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> 

</div>
  • 写回答

2条回答 默认 最新

  • dongyoufo5672 2015-09-28 21:56
    关注

    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.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源