3

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.

1
  • you can use onchange handler Commented Feb 13, 2013 at 8:26

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.com';
}
</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> 

Comments

1

You are looking for Autocomplete

1 Comment

actually not! I want to update other fields. please read my last edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.