简体   繁体   中英

select + text input form field at the same time?

How can I make my select be also an input form filed at the same time?

I want it to have options for example 0.01 to 10.00 and to also make sure it has 2 decimals

How can I make it work in jquery?

It sounds like you need a combobox with some validation. Have a look at: http://jqueryui.com/autocomplete/#combobox

您可能需要微调框而不是选择框: http : //jqueryui.com/spinner/#decimal

I can give you code which will select a option and auto generate a input type of textbox and insert the selected value to be used by the form . This is a tested code .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>test select</title>
   <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 

    <script>
        $(document).ready(function () {
            $('#pickValue').change(function () {
                var x =$(this).find('option:selected').text();
                if($('#myval').length == 0)
                    $('#showData').append('<input type="text" name="myval" id="myval" value="'+x+'" >');
                else
                    $('#myval').replaceWith('<input type="text" name="myval" id="myval" value="'+x+'" >');
            });
        });

    </script>
</head>
<body>
    <form action='xyz.php' method='get'>
        <div id='showData'>
            <select id='pickValue'>
                <option>Pick value</option>
                <option value='0.1'>0.1</option>
                <option value='0.2'>0.2</option>
                <option value='0.3'>0.3</option>
            </select>
        </div>
    </form>

</body>
</html>

I have attached full code you can use it as you wish to .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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