jsmorris
jsmorris

Reputation: 319

How to set focus to a textbox that was just inserting it into my page?

I have a dynamic web page that after clicking a link, I insert a partial view into my page using brailjs action. My brailjs view looks like this

page.inserthtml('bottom', 'items', { @partial: 'item/_fields_replacement_part' })
page.replacehtml('add_item_link', { @partial: 'item/_addlink_replacement_part' })

After I insert the html, I want to be able set focus to one of the textboxes that was just inserted. How can I do that?

Upvotes: 0

Views: 88

Answers (1)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99730

Say you have this js function:

function setFocus(id) {
   document.getElementById(id).focus();
}

You can call it from brailjs like this:

page.call('setFocus', 'myElementId');

Upvotes: 1

Related Questions