doulu1945 2018-07-24 19:44
浏览 64

我想将文本输入切换到带有选项 - > MYSQL的下拉列表

I currently have a form that has text entries that input properly into a database.

ON the last entry I want to switch it from text input to a drop down list. Here is my current code:

    <div class="form-group">
    <label for="equipment">Equipment:</label>
    <input type="text" id="equipment" name="equipment" value="<?php echo isset($equipment) ? $equipment : ''; ?>" />
    <span class="validity"></span>
    </div>

This is the code I tried switching it to:

<script type="text/javascript">

function showfield(name){

if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';

else document.getElementById('div1').innerHTML='';

}

</script>



<select name="equipment" id="equipment" onchange="showfield(this.options[this.selectedIndex].value)">

<option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>">53v</option>
<option value="53R" <?php echo (isset($equipment) && $equipment == '53R') ? 'selected="selected"' : ''; ?>">53r</option>
<option value="53F" <?php echo (isset($equipment) && $equipment == '53F') ? 'selected="selected"' : ''; ?>">53f</option>
<option value="Other">Other</option>

</select>

<div id="div1"></div>

Am I close at all?

EDIT: I edited based on Raptord's advice

Now I'm getting:

Error 2031 No data supplied for parameters in prepared statement

ADDED:

CREATE TABLE `details` (
  `id` int(11) UNSIGNED NOT NULL,
  `contactname` varchar(255) DEFAULT NULL,
  `phonenumber` varchar(255) DEFAULT NULL,
  `equipment` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

EDIT (REVISED CODE):

<script type="text/javascript">

function showfield(name){

if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';

else document.getElementById('div1').innerHTML='';

}

</script>

<div class="form-group">
<label for="equipment"><sup>*</sup> Equipment:</label>

<select name="equipment" id="equipment" onchange="showfield(this.options[this.selectedIndex].value)">
<option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>">53V</option>
<option value="53R" <?php echo (isset($equipment) && $equipment == '53R') ? 'selected="selected"' : ''; ?>">53R</option> 
<option value="53F" <?php echo (isset($equipment) && $equipment == '53F') ? 'selected="selected"' : ''; ?>">53F</option>
 <option value="Other">Other</option> </select> <div id="div1"></div>
</div>
  • 写回答

1条回答 默认 最新

  • dtufl26404 2018-07-24 20:05
    关注

    Your option tags should look something like this, rather than having 2 value attributes:

    <option value="53V" <?php echo (isset($equipment) && $equipment == '53V') ? 'selected="selected"' : ''; ?>>53v</option>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用