如何获取文本框中输入值或javascript中选定选项的值?

如何获取文本框中输入值或javascript中选定选项的值?,javascript,jquery,Javascript,Jquery,我有一个弹出窗口,提示用户从下拉菜单中进行选择,如果数据库中没有,则有一个文本框供用户输入数字 我想抓住用户选择做的任何事情的价值,即任何一个选择(2个中的1个,而不是两个都),并用这个价值做一些事情。我的问题是如何在javascript或jquery中做到这一点 这是我的html/php代码 <table> <tr> <td class='Fnumber'> <span><?php xl('Send to', 'e');

我有一个弹出窗口,提示用户从下拉菜单中进行选择,如果数据库中没有,则有一个文本框供用户输入数字

我想抓住用户选择做的任何事情的价值,即任何一个选择(2个中的1个,而不是两个都),并用这个价值做一些事情。我的问题是如何在javascript或jquery中做到这一点

这是我的html/php代码

  <table>
    <tr>
    <td class='Fnumber'> <span><?php xl('Send to', 'e'); ?>:</span></td>
    </tr>
    <tr>
    <td>
            <select id='numberinfo' name='send_to'>
            <?php
            echo "<option value='' selected='selected'>Select Number Destination</option>";
            foreach($send_to as $key => $value) {
                    echo "  <option value='$value' ";
                    echo ">$value </option>\n";
             }
            ?>
            </select>
    </td>
    </tr>
    <tr>
    <td class='Fnumber'><span><?php echo "OR" ?></span></td>
    </tr>
    <tr>
    <td class='Fnumber'><span><?php xl('Enter Your Number', e); ?>:</span></td><br/>
    <tr>
    <td class='Fnumber'>
    <input type="text" class="clearable" name="send_to" placeholder="Enter Your Number" maxlength="10" onkeypress="return isNumberKey(event)"/>
    </td>
    </tr>

    </table>

:
:

这个逻辑行吗?假定

<select id='numberinfo' name='send_to'>
   <option value='initialvalue' selected="selected">Select One</option>
   <option value='value1'>Select One</option>
   <option value='value2'>Select One</option>
</select>
<input id="inputtext" type="text" placeholder="Input Number"/>
您可以检查输入是否已更改


或者使用预定义值

当用户在这两个字段中放置某个内容时,哪个是更高的优先级?下拉菜单应该具有更高的优先级,但如果他们找不到该值或希望放置其他数字,文本框就在那里。此逻辑是否可行?如果(dropdown.value==defaultvalue){finalvalue=textbox.value}或者{finalvalue=dropdown.value}都德,在页面a的正下方有一个答案框。只需再滚动一点。评论最好是留给尖刻的陈述和抱怨。逻辑会有帮助的,我正试图把它翻译成代码:)太棒了,非常感谢DeckyFx!!!这对我来说是可行的,我曾试图执行getElementsByName(),但却被弄糊涂了。
var finalvalue = "";
if ($("#numberinfo").val() == 'initialvalue') {
    if ($("#inputtext").val().length > 0) {
        finalvalue = $("#inputtext").val();
    }
} else {
    finalvalue = $("#numberinfo").val();
}
if (finalvalue.length == 0) {
    alert("Please input one of two")
} else {
    alert("Inputed: " + finalvalue)
}