HTML Forms - when the text box value changes - html

I'm trying to figure out how to call a method everytime a text box in a form's value changes.
For example,
Is there a parameter I can add that is called everytime the user types something new in the box? I know there is an "onchange" but that is only called once the user is done typing in that box.
Thanks!

What you need to us is an onkeyup event. Without a js library your code should look similar to this (syntax is unchecked):
<html>
<head>
<script type="text/javascript">
function keyup(x)
{
//code
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname" onkeyup="keyup(this)">
</body>
</html>
You can also use onblur if you want to check it when the user changes focus from the text box.
For more detail:
http://www.w3schools.com/jsref/event_onkeyup.asp
http://www.w3schools.com/jsref/event_onblur.asp

Related

suppress Chrome default message onmouseover when Required Attribute is set

I am developing a form in html5, I have put the required attribute and customized the tool tip. When I press the submit button the customized tooltip appears however when I hover over the field I see default message "please fill out this field" in addition to custom tooltip post submission attempt or only default message pre submission. I like either to translate the default message or suppress it. The behavior is unique to chrome. Any help will be much appreciated.
I have tried using the setCustomValidity() onmouseover event but in vain
Regards
Yasir Munir
<html>
<head>
<script>
function validator(input) {
input.setCustomValidity('my custom message');
}
</script>
</head>
<body>
<form>
<input type="text" required onmouseover="validator(this)" oninput="validator(this)" />
<input type="submit" />
</form>
</body>
</html>

In an HTML form, how do I copy content of one field to another

I need a button that takes information that you have entered into one div, and put it into another. Basically I have one div that asks for delivery information, while the other asks for billing info. I want to have a button you can press that checks if you have filled out the delivery info then pressing the button would make the information entered into the delivery information transfer to the billing info. How would I make a button do that?
Javascript:
<script language="javascript">
document.getElementById('your-button').addEventListener("click", moveContent);
function moveContent() {
document.getElementById('your-div').textContent = document.getElementById('other-div').textContent;
}​
</script>
HTML:
<button id="your-button">Move Content</button><br />
<div id="other-div">This Text will go into the div below</div>
<div id="your-div">Click button to move text from above text here</div>
Make a form, then create an <input onClick="copy();" type="button" > tag. Create a javascript function copy that copies the data. Do not add a submit attribute to the form.
I.e.,
<script type="text/javascript">
function copy()
{
//Copy the data from one div to another. I recommend setting ID attributes and using document.getElementById(id);
}
</script>
<form>
<input onClick="copy();" type="button" value="Copy data!" ></input>
</form>

Div content not refreshing in IE (screen refresh)

my application working well in all browsers except IE.
In my application I have a div popup form which contains some fields. In the text box it i pressed any key it was not displaying. If i move the mouse then the entered texts are displaying actual thing is screen not refreshed
How to solve this.
mycode:
<form>
//this is popup form
<div>
<form>
<input type="text"/>
<!-- if i type in the text box in IE it is not displaying but in some pc only -->
</form>
</div>
</form>
Thanks,
If i understand correctly, you want to have a popup, containing a form. The code you pasted is just html; it does not have any of this interactivity.
Let's start with your code. It has a form with a form inside it. The form tag is used to specify the start of a web form. You can specify several thing in this tag:
action: Where will the form be posted to? e.g. send the form to http://www.example.com/processform/
method: Will the form be submitted using the GET or POST method?
Having a second form tag inside it doesn't make sense: your browser will not know where to post the form to. Most browsers will choose to use one of the two tags, but they might choose the wrong one or ignore the form tags entirely.
If you want to have a form in a popup, use an approach like following html code:
<p><span id="clickablelink">Open the form</span></p>
<div class="dialog" style="display: none;">
<form action="/process/" method="post">
<input type="text" />
<input type="submit" name="submit" value="Submit this form" />
</form>
</div>
This code part should be inside the part of your html document.
You cannot open a dialog in the same page, unless you use JavaScript, jQuery or another framework to display this form. An example of this using jQuery UI:
<link type="text/css" href="css/themename/jquery-ui-1.7.1.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript">
$(function() {
$(".dialog").dialog({
autoOpen: false
});
$("#clickablelink").click(function(){
$(".dialog").dialog("open");
});
});
</script>
This code block should be inside the part of your html document.
This is just a basic example. It might not be exactly what you are looking for. It is meant to show you in what directions you can look for your specific solution. I would suggest putting more details in your question:
For what purpose are you using this website?
What will this form be used for?
Why are you displaying a form inside a dialog?
Answering these questions and specifying your problem help you understand what you are trying to achieve and help us to answer your question properly.
You can read more about forms and javascript dialogs at the following links:
http://www.w3schools.com/html/html_forms.asp
http://mdrisser.r1designs.net/blog/?p=3
And for information about the jQuery framework:
http://www.jquery.com
http://ui.jquery.com

How can I prevent WebKit browser to submit a form when enter is pressed in an input [duplicate]

This question already has answers here:
Prevent users from submitting a form by hitting Enter
(36 answers)
Closed 6 years ago.
When using a form with many text input, WebKit/Safari/Google Chrome submits the form when ''enter'' is pressed in any input element. Even if there is no submit input element and no onclick handler registered.
See for instance this sample code:
<html>
<body>
<form method="POST" action=".">
<ul>
<li><input type="text" name="foo" value="<?=rand()?>"/></li>
<li><input type="text" name="bar" value="<?=$_POST['foo']?>"/></li>
</ul>
</form>
</body>
</html>
When pressing enter in any of the two text input elements, the form is submitted.
Since I'm handling my form in JavaScript with asynchronous HTTP requests, I need to prevent this behavior. I could register a custom handler for the keypressed event to preventDefault and stopPropagation . But its seems ugly and is not really practical when new text input elements are added dynamically.
Listen for the onsubmit event on the form and return false.
If you don't ever want the form to submit, don't include a <form> element at all. It's valid to include free-standing form field elements.
value="<?=$_POST['foo']?>"
XSS vulnerability. You need to htmlspecialchars() all text-to-HTML output.
Daniel A. White is right, but since I got a little bit confused by the answer, maybe it should be clearly stated that the return false should be on the event:
function goWithSubmit(e)
{
if (e) e.returnValue=false;
}

HTML textbox, auto highlighting text

How would I make a textbox, containing preexisting text, that when the user clicked within it all the text inside it would become highlighted. For example, the same way YouTube does the textboxes for the embed code on their videos. Thanks
If I've understood your problem correctly, you could use some javascript (untested code):
<script language="JavaScript">
function selectText(textField)
{
textField.focus();
textField.select();
}
</script>
<input type="text" name="sometext" size="100" value="The Text" onClick='selectText(this);'>
You can put the script between your <head> and </head> tags.