Saumil Sapariya
Saumil Sapariya

Reputation: 11

Custom focus on Asp.net elements

I am new user at stackoverflow. I am facing issue to set custom focus on certain elements on asp.net. We can use asp.net or java script functionality.

My current page layout

I want to focus on first with page load on payment 1 text box then payment mode 1 dropdown and then save button.

Thank you in advance for your time.

Upvotes: 1

Views: 187

Answers (3)

Roger Walsh
Roger Walsh

Reputation: 339

You shouldn't need any JS for this. Just use autofocus

<input type="text" name="payment1" tabindex="1" autofocus />

So now on page load that field should be focussed. then tabindex the other fields in the order you want them to focus.

Upvotes: 0

Kljuka
Kljuka

Reputation: 63

You can do all that using HTML and JavaScript:

First assign an id attribute to the payment_1 element. For example (ad "id" to input html element):

<input id="payment1">

Then using JavaScript focus that input field:

document.getElementById('payment1').focus();

If you want your users to have the ability to move between input fields with a "Tab" button in a different order than the default (left to right, up to down), then assign tabindex attribute to elements. For example:

<input id="payment1" tabindex="1">
<button id="save" tabindex="2">

Upvotes: 1

Jigarb1992
Jigarb1992

Reputation: 848

You can give the TabIndex from control property in asp.net or you can use jquery to set focus by $("element").focus()

Upvotes: 1

Related Questions