开发者

Get Text box value using Java script

I have two text boxes. Country and City. I am using type ahead in city text box. I want to show the city name according to the country which i typed. How can i pass country value using java script to my PHP function to get 开发者_开发技巧correct city name.


You could use AJAX to send the country name to your PHP function.

But you could also do it with Javascript like this if you do not need to determine the city dynamically from the server side.

    <script type="text/javascript">
        function sync() {
            var country = document.getElementById('country').value;
            var city = document.getElementById('city');
            switch (country) {
                case 'China':
                    city.value = 'Shanghai';
                    break;
                case 'France':
                    city.value = 'Pairs';
                    break;
            }
        }
    </script>

    <html>
        <form style="text-align:center">
            Country:<input id="country" type="text" title="Country" onblur="sync()"/><br/>
            City:<input id="city" type="text" title="City"/><br/>
        </form>
   </html>


Try this:

document.getElementById('yourCountryidhere').value
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜