...

View Full Version : setting focus to current form element



jntcomputers
06-30-2006, 01:45 PM
I am trying to set the focus to the current element in a javascript. I can't specify the field name because the script is used site wide. It is placed in an a href tag, but I am open to suggestions!

Thanks!!!

Bill Posters
06-30-2006, 01:58 PM
I'm not entirely sure what you mean.
What do you mean by the 'current' element?

Do you have a url where we can see what you're referring to?

jntcomputers
06-30-2006, 04:04 PM
I'm not entirely sure what you mean.
What do you mean by the 'current' element?

Do you have a url where we can see what you're referring to?

The url is www.safetypilots.com/dev/admin/schedule.php (login=school1/iceman). To the left there is a javascript popup calendar with date field. What I am tring to do is set the date using the script (works as expected), but I need the form to be submitted when a new date is selected. I tried onChange="this.form.submit" in the date field, but that doesn't work. OnFocus does work, but I need to somehow implement a set focus to the date field when the script enters the date.

jkd
06-30-2006, 04:18 PM
this.form.submit()

would be what is required to submit the form.

Beagle
06-30-2006, 04:22 PM
You should probably stick with onchange, so that if the user manually enters it it submits.

Then, you need to fire the onchange event if you set the value using javascript:



// *** Credit to PPK at www.quirksmode.org for the education on this ***
function dispatchEvent(p_element, p_event)
{
if (p_element.fireEvent) // *** IE event dispatching ***
p_element.fireEvent("on" + p_event);
else // *** !!!NOTE!!! NOT DEFENSIVE ***
{ // *** DOM event dispatching ***
var evt = document.createEvent("HTMLEvents");
evt.initEvent(p_event, true, true);
p_element.dispatchEvent(evt);
}
} // *** End Function: dispatchEvent(p_element, p_event) ***

dispatchEvent(document.getElementById('yourDateField'), 'change');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum