我有一个下拉输入选择“评估测试类型”,根据选择某些数据出现在它下面的提交按钮.现在我添加到:“评估测试类型”默认值为< option selected ='selected'>< / option>但是,如果选择了该选项并单击了submit1,我想阻止提交按钮出现
- $options = '';
- $filter=MysqL_query("select afnumber from employees WHERE Status='Employed'");
- while($row = MysqL_fetch_array($filter)) {
- $options .="<option >" . $row['afnumber'] . "</option>";
- }
- $menu="<form id='filter' name='filter' method='post' action=''>
- AFNumber : <select name='SelectAF' id='filter' style='color:grey;'>" . $options . "</select>
- Evaluation Test Type : <select name='Type' id='type' style='color:grey;'><option selected='selected'></option><option value='loyalty'>Loyalty</option><option value='performance'>Performance</option></select>
- <input type='submit' name='submit1' value='Submit' style='width:80px; height:30px; text-align:center; padding:0px;'>
- </form>
- <br>
- ";
- echo $menu;
- if(isset($_POST['submit1']))
- {
- $type = $_POST['Type'];
- $MysqLi = new MysqLi("localhost","root","Js","jr");
- /* check connection */
- if ($MysqLi->connect_errno) {
- printf("Connect Failed: %s\n",$MysqLi->connect_error);
- exit();
- }
- if ( $result = $MysqLi->query( "SELECT questiontext FROM questioninfo WHERE type='$type'" ) ) {
- $html=array();
- $html[]="
- <form action='' method='post' id='quiz'>
- <ol>";
- $counter=1;
- while( $row = $result->fetch_array() ) {
- $question=$row['questiontext'];
- $answerA=1;
- $answerB=2;
- $answerC=3;
- $answerD=4;
- $answerE=5;
- $html[]="
- <br/>
- <h3>Question {$counter}: {$question}</h3>
- <li>
- <br/>
- <input type='radio' name='question-{$counter}-answers' id='question-$counter-answersA' value='1' />
- <label for='question-{$counter}-answers-A'> {$answerA} </label>
- <br/>
- <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersB' value='2' />
- <label for='question-{$counter}-answers-B'> {$answerB} </label>
- <br/>
- <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersC' value='3' />
- <label for='question-{$counter}-answers-C'> {$answerC} </label>
- <br/>
- <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersD' value='4' />
- <label for='question-{$counter}-answers-D'> {$answerD} </label>
- <br/>
- <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersE' value='5' />
- <label for='question-{$counter}-answers-E'> {$answerE} </label>
- </li>";
- $counter++;
- }
- $html[]="
- </ol>
- <input type='submit' name='submit' value='Submit' style='width:80px; height:30px; text-align:center; padding:0px;'>
- <input type='hidden' name='type' value='{$type}' />
- </form>";
- echo implode( PHP_EOL,$html );
- $result->close();
- }
- }
- if( isset( $_POST['submit'] ) ){
- $MysqLi = new MysqLi("localhost","jr");
- if ($MysqLi->connect_errno) {
- printf("Connect Failed: %s\n",$MysqLi->connect_error);
- exit();}
- if ($result = $MysqLi->query("SELECT * FROM questioninfo WHERE Type='performance'")) {
- $row_cnt = $result->num_rows;
- $result->close();
- }
- if ($result = $MysqLi->query("SELECT * FROM questioninfo WHERE Type='loyalty'")) {
- $row_cnt1 = $result->num_rows;
- $result->close();
- }
- $numQuestions=$row_cnt;
- $numQuestions1=$row_cnt1;
- $type = $_POST['type'];
- if($type == 'performance')
- {
- for( $counter=1; $counter <= $numQuestions; $counter++ ){
- $type = $_POST['type'];
- $answer = $_POST['question-'.$counter.'-answers'];
- $sql="insert into `question` (`Type`,`Value`) values ('".$type."','".$answer."')";
- $MysqLi->query($sql);
- }
- }
- else if($type == 'loyalty')
- {
- for( $counter=1; $counter <= $numQuestions1; $counter++ ){
- $type = $_POST['type'];
- $answer = $_POST['question-'.$counter.'-answers'];
- $sql="insert into `question` (`Type`,'".$answer."')";
- $MysqLi->query($sql);
- }
- }
- else
- {
- }
- }
如果您只想阻止用户选择空白选项,只需使用
disabled
属性即可.然后为选择元素使用
required
属性,以防止它们以空白的“评估测试类型”值提交.不要忘记在所需属性的空白选项上添加value =“’,以响应
here.
- Evaluation Test Type :
- <select name='Type' id='type' style='color:grey;' required>
- <option value='' selected disabled></option>
- <option value='loyalty'>Loyalty</option>
- <option value='performance'>Performance</option>
- </select>