Jump to content

[SOLVED] Display value in two different fields!


budimir

Recommended Posts

Hey Guys,

 

I'd like when a user enters a date that it's displayes in two different input boxes. I have tried searching on google but only thing I come up is that I can display it in alert box.

 

This is the code I found, but it's not suting my needs.

<script type="text/javascript">
function notEmpty(){
var myTextField = document.getElementById('myText');
if(myTextField.value != "")
	alert("You entered: " + myTextField.value)
else
	alert("Would you please enter some text?")		
}
</script>
<input type='text' id='myText' />
<input type='button' onclick='notEmpty()' value='Form Checker' />

 

So, I want.

 

In input box1 user enters a date and at the same moment that date is displayed in input box2.

 

Any solutions?

 

You can point me to the web page that can help me!!

 

Thanks.

Link to comment
Share on other sites

I believe you want to take a look at the OnKeyPress/KeyDown/KeyUp Events.

 

With it you can update elements on screen when they type into a text box, like this simple function:

 

<script type="text/javascript">

// Function Called "copyfield" Arguments: (Copy From,Copy To,Within Form...)
function copyfield(field,mirror,formblock){

// Shortcut to the Form element' Namespace
with(formblock){

	// Shortcut and Store the new textbox value
	with(field){
		var cText = value;
	}

	// Shortcut and copy the stored value to the mirror text box
	with(mirror){
		value = cText;
	}
}
}
</script>
<form name="form1" id="form1">
<input type='text' name='dobinput' onkeyup='copyfield(dobinput,mirrorinput,form1)' value='Date of Birth' /> -- 
<input type='text' name='mirrorinput' disabled>
</form>

 

The function can be used with any fields, can update any field from any field as long as they are in the same form block.

 

Hope this helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.