javascript - If语句在javascript函数中的选择框值

标签 javascript php html

我在指向选择框的 PHP 页面上用 javascript 编写 函数 时遇到问题。这个if语句是指向选择框

if (!(document.getElementById("add_product").value)==="Choose here")

代码如下:

                     function promptEnrollmentMonth() {
                         if (!(document.getElementById("add_product").value)==="Choose here") {
                             var month = prompt("Is this the correct month for this course/product?", "<?php echo "$EnrollmentMonth"; ?>");
                             if (month !=null) {

                             }
                         }
                     }

 <button type="submit"
 onclick="promptEnrollmentMonth()">Update</button>

 <div>Add course/product:<select name='add_product'>
 <option selected>Choose here</option> 
 <option>Other options...</option>
 </select></div>

最佳答案

第一个问题是 "<?php echo "$EnrollmentMonth"; ?>"

应该是这样的:

var month = prompt("Is this the correct month for this course/product?", "<?php echo $EnrollmentMonth; ?>");

第二 <option selected>Choose here</option>您还没有为选项标签提供值属性:

<option value='Choose here' selected>Choose here</option> 

关于javascript - If语句在javascript函数中的选择框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44666480/

相关文章:

javascript - ASP.NET 网站的 AJAX 购物车

php - 使用 Laravel 应用程序发送大量电子邮件

android - 强制 HTML5 应用程序处于横向模式

javascript - 如何使用 jQuery 访问输入字段文本?

javascript - 在代码沙箱中使用 npm 包对 Web Worker 使用react

php - PHP5 中可以访问文件系统的函数的完整列表是什么?

php - Android 使用 PHP 连接 MYSQL

php - JQuery - 上传裁剪并保存到 MySQL 数据库

javascript - html 自定义元素使主机 css 应用于影子 dom 子代

javascript - 使用 HTML 和 CSS 制作动画 parking 场网格