PDA

View Full Version : filling in field on leaving



esthera
Jun 7th, 2006, 07:18 PM
I have a form with 15 date fields. all named date1 ,date2, date3 accordingly.
How can I make it that as I leave each field the next date field is updated with the date in the field I am leaving?

vwphillips
Jun 8th, 2006, 01:04 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/


function NxtDate(obj){
var eles=obj.form.elements;
var fnd;
for (var zxc0=0;zxc0<eles.length;zxc0++){
if (fnd&&eles[zxc0].name.match('date')){
eles[zxc0].value=fnd.value;
break;
}
if (eles[zxc0]==obj){
fnd=eles[zxc0];
}
}
}



/*]]>*/
</script>

</head>

<body onload="">
<br /><br />

<center><form>
Date 1 <input type=text name="date1" onblur="NxtDate(this);" /><br />
Another <input type=text name="A1" /><br />
Date 2 <input type=text name="date2" onblur="NxtDate(this);" /><br />
Another <input type=text name="A2" /><br />
Another <input type=text name="A3" /><br />
Another <input type=text name="A4" /><br />
Date 3 <input type=text name="date3" /><br />
</form>
</center>


</body>

</html>

Arty Effem
Jun 8th, 2006, 03:22 AM
I have a form with 15 date fields. all named date1 ,date2, date3 accordingly.
How can I make it that as I leave each field the next date field is updated with the date in the field I am leaving?Add this code somewhere below your form. At the bottom of the script, alter the parameter in the function call to match the name of your form.

E.G. If your form were called dateForm, you would have:


copyLastDate(document.forms.dateForm);

That's all you need to do; there's no need to add anything to the form elements.


<SCRIPT type='text/javascript'>

function copyLastDate(theForm)
{
var length=theForm.elements.length;

for(var i=0, lastField=-1, elem; i<length; i++)
if( /date\d+/i.test((elem=theForm.elements[i]).name) )
{
if(lastField != -1)
theForm.elements[lastField].onblur=new Function("this.form.elements["+i+"].value=this.value");
lastField=i;
}
/*28432953204368616C6D6572732032303036*/
}

copyLastDate(document.forms.myForm);

</SCRIPT>

esthera
Jun 8th, 2006, 08:17 AM
my date is actually chosen with a date picker.

for some reason the onblur is not having effect when the datepicker is used.
what should I use instead?

esthera
Jun 8th, 2006, 07:33 PM
any idea what i can use besides onblur to get this working??
I am using a date picker to get teh date

Beagle
Jun 8th, 2006, 07:42 PM
When you select a date from the date picker make sure to do a date1.focus() so that it can blur.

esthera
Jun 9th, 2006, 07:15 AM
where would I put that?

i'm using the datepicker from http://www.javascriptkit.com/script/script2/tengcalendar.shtml

Beagle
Jun 9th, 2006, 09:02 PM
I don't have the time to go through the code for the datepicker. You're going to have to figure out where in the script the field gets filled with it's data. (like something.value = date) Then, just do a something.focu(). The next click someone makes will cause the field to blur.

esthera
Jun 19th, 2006, 07:41 PM
if I want to do the same thing with a select box

meaning when leaving type1 set type2 to the selected value of type1--
how would I do this?