koushikgattu Posted January 11, 2008 Share Posted January 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
jos. Posted January 11, 2008 Share Posted January 11, 2008 If you are then posting this info to a PHP script it would be a lot easier to parse the date when it gets to the server with PHP explode() function; and much more reliable too! Jos. Quote Link to comment Share on other sites More sharing options...
koushikgattu Posted January 11, 2008 Author Share Posted January 11, 2008 Can't we do this by using javascript? we can split that value of the textbox(mm//dd/yy) using split("/") some thing link this ..but how to put that values in the appropriate text boxes? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 12, 2008 Share Posted January 12, 2008 <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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.