Update HTML form with Javascript while typing - Stack Overflow

I can update an HTML form using Javascript, when the user hits enter when on something on the form or w

I can update an HTML form using Javascript, when the user hits enter when on something on the form or when he triggers the onclick event on the "submit" button, but I want the form to be updated while the user is typing something.

I know that I can do Infinity loop, yet it is not a good idea; or I can check after intervals but it will cause unnecessary checking, which I don't want.

I can update an HTML form using Javascript, when the user hits enter when on something on the form or when he triggers the onclick event on the "submit" button, but I want the form to be updated while the user is typing something.

I know that I can do Infinity loop, yet it is not a good idea; or I can check after intervals but it will cause unnecessary checking, which I don't want.

Share edited Oct 31, 2016 at 16:29 matec 1,5251 gold badge12 silver badges23 bronze badges asked Feb 13, 2013 at 8:19 sadaf2605sadaf2605 7,56010 gold badges67 silver badges105 bronze badges 1
  • you can use onchange handler – Hary Commented Feb 13, 2013 at 8:26
Add a ment  | 

3 Answers 3

Reset to default 3

Use keyUp event handler with the input field contained within your form.

References: Javascript, jQuery

[UPDATE]

You missed round brackets at function definition, check the updated fiddle

I had the same question and based on this post and sohel's answer I managed to get it working. Now I would like to share my solution in form of a short working example: If you type your name in the first field it will suggest an email address in the second one.

<!DOCTYPE html>
<html>
<head>
<script> 
function nameModify(emailElement, nameElement) {

        emailElement.value = nameElement.value + '@stackoverflow.';
}
</script>
</head>
<body>
<form name="aform" action="#"> 
        <input type="text" name="name" onkeyup="nameModify(this.form.elements['email'], this);" >
        <input type="text" name="email" >
</form>
</body>
</html> 

You are looking for Autoplete

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745073278a4609683.html

相关推荐

  • Update HTML form with Javascript while typing - Stack Overflow

    I can update an HTML form using Javascript, when the user hits enter when on something on the form or w

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信