0

So i have two pages and one has a list of buttons (page a) and the other page only has one(page b). Im looking for a way that if you press the button on page b it will take me to page a with the second button with .focus() already targeting it. here are some links for the code i have written this is for page a http://jsfiddle.net/posgarou/S96zw/

HTML page a

<button type="button" id="button0" onClick="reply_click(this.id)">button0</button><p></p>
<button type"button" id="button1" onClick="reply_click(this.id)">button1</button><p></p>
<button type"button" id="button2" onClick="reply_click(this.id)">button2</button><p></p>
<textarea id="myArea"></textarea>
<button type"button" id="button0" onClick="reply_click(this.id)">focus on button 0</button><p></p>

JAVASCRIPT (just used the same for both pages)

function reply_click(clicked_id){
  var id= clicked_id;
  var myTextArea = document.getElementById('myArea');
  myTextArea.innerHTML += id;
  document.getElementById(id).focus(); 
};

and this is for page b http://jsfiddle.net/posgarou/S96zw/

HTML <body> <textarea id="result"></textarea> <button type="button" id="return" onClick="reply_click(this.id)">Return</button> </body>

michael
  • 11
  • 1

1 Answers1

0

You should be able to do that using either a cookie or (better) local/sessionStorage.

On page b, you would include the following code:

sessionStorage["focusedButton"] = "buttonId";

and on page a, you would include the following:

if (sessionStorage["focusedButton"] != undefined) {
    document.getElementById(sessionStorage["buttonId"]).focus();
}

For more info, see this earlier question.

Community
  • 1
  • 1
Ryan Mitchell
  • 754
  • 5
  • 8