繁体   English   中英

我无法从组合框获得想要的值

[英]I can't get the value I want from a combobox

我想在组合框中的对象中添加一个新值,并且在执行该操作时,就像我对其他值所做的操作一样,我收到一条消息,提示它未定义。 任何想法如何解决它?

main.js

$(document).ready(function () {
    //the ip-address will have to change to the ip of the host of the app.
    //in my case the ip is 192.168.1.68
    var conn = new WebSocket('ws://localhost:8080'); 
    var chatForm = $(".chatForm"),
        messageInputField = chatForm.find("#message"),
        messagesList = $("#container"), //taked the name container to match the name of the css and work with the jquery draggabilly
        usernameForm = $(".username-setter"),
        usernameInput = usernameForm.find(".username-input"),
        comboBox = $(".comboboxvalue"),
        category = comboBox.find("#indexNr");

index.php

<div class="container">
        <div class="row">
            <div class="col-md-push-2 col-md-8">
                <h2>WorkShoppy Messages Application</h2>
                <h3>Username:  <span class="username label label-primary" ></span></h3>
                <div class="row" id="set">
                    <form class="username-setter" action="index.php" method="post">
                        <div class="form-group">
                            <label for="">Set username</label>
                            <input type="text" name="name" value="" class="form-control username-input" >
                        </div>
                        <button class="btn btn-primary pull-right" name="button" id="btn" onclick="myFunction()">Set</button>
                    </form>
                </div>
                <label for="indexNr">Category</label>
                <br>
                <select id="indexNr" id="indexNr" name="indexNr">
                    <option value="positive" class="comboboxvalue">Positive</option>
                    <option value="negative" class="comboboxvalue">Negative</option>
                </select>
            </div>
        </div>
</div>

任何想法如何解决这一问题?

替换这些行

 comboBox = $(".comboboxvalue"),
    category = comboBox.find("#indexNr");

category =     $("#indexNr").val()

要么

category = $("#indexNr option:selected").val();

还将其他id属性删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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