Jump to content

javascript form validation help


koushikgattu

Recommended Posts

Hi,

 

Is there any way that i could copy the one text box value into multiple text boxes(but part of the value)

 

Lets say, i i have one text box for date (format mm/dd/yy) <input name="completedate" value="" type="text">

 

I want that value of the text box to be pasted on to three different text boxes.(mm in one textbox...date one text box and year in one text box)

<form name="submitdate" method="post" id="submitdateForm" action="" >

 

<input name="completedate" value="" type="text">

 

 

<input name="date" value=""  type="text">

 

<input name="month" value=""  type="text">

 

<input name="year" value=""    type="text">

 

</form>

To hide these three text boxes from display..i can put type="hidden".

 

Can any one  please help me with this?

 

thanks

Link to comment
Share on other sites

<script language="javascript">
function slicer()
{
var cd = document.getElementById('completedate').value
var section = cd.split("/");
document.getElementById('field1').value = section[0];
document.getElementById('field2').value = section[1];
document.getElementById('field3').value = section[2];
}
</script>

Complete Date: <input type="text" id="completedate"><br><br>
Month: <input type="text" id="field1"><br><br>
Date: <input type="text" id="field2"><br><br>
Year: <input type="text" id="field3"><br><br>
<input type="button" value="Split'em Up" onclick="slicer()">

 

or

 

<script language="javascript">
function prep()
{
var cdl = document.getElementById('completedate').value.length;
var e = (evt.which) ? evt.which : event.keyCode;
if (e !=  {
if (cdl == 2) {
document.getElementById('completedate').value = document.getElementById('completedate').value + "/";
}
else if (cdl == 5) {
document.getElementById('completedate').value = document.getElementById('completedate').value + "/";
}
}
}
function slicer()
{
var cd = document.getElementById('completedate').value;
var section = cd.split("/");
document.getElementById('field1').value = section[0];
document.getElementById('field2').value = section[1];
document.getElementById('field3').value = section[2];
}
</script>

Complete Date: <input type="text" id="completedate" onblur="slicer()" onkeydown="prep()" maxlength="10"><br><br>
Month: <input type="text" id="field1"><br><br>
Date: <input type="text" id="field2"><br><br>
Year: <input type="text" id="field3"><br><br>

 

 

You can set: field1, field2, and field3 to hidden fields if you would like to; I just did it this way to show you a good example of how to do what you wanted to do.

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.