Form contains input elements and submit button. Pressing Submit button shows pdf file in new tab in browser.
If enter is pressed to show report, focus moves to submit button. After selection report parameters tag again additional click in input element is required to enter new value to same element.
How to keep focus input element where enter was pressed ?
<form id="Form" class='form-fields' method='post' target='_blank'
action='Render'>
<input id='test' name='test' value='test' />
...
<input id='_submit' type='submit' value='Show report' />
</form>
jquery, jqueryui, asp.net mvc2 are used.
update
I have 2 elements with same name in form to allow unchecked checkbox submission:
<input type='hidden' value='false' name='Summary' />
<input type='checkbox' id='Summary' name='Summary' checked />
<select class="ui-widget-content ui-corner-all" id="_Report" name="_Report" size="10">
<option value="LV001">Report1</option>
<option value="LV003">Report2</option>
<option selected="selected" value="LV009">Report3</option>
</select>
I tried code below as suggested in comment. If focus is in checkbox, it focus is not restored. Instead select element is focused. How to fix ?
$("#Form input:not([type=submit]), textarea, select").focus(function () {
$('input').removeClass('hasFocus');
$(this).addClass('hasFocus');
});
If you want to get back to the last focused item, I think you will need to keep track on the last focused item.
Something like this will probably achieve what you are looking for:
I also made a jsfiddle to test: http://jsfiddle.net/Jht6C/