views:

45

answers:

2
  function insertParamIntoField(anchor, param, field) {
       var query = anchor.search.substring(1, anchor.search.length).split('&');

       for(var i = 0, kv; i < query.length; i++) {
          kv = query[i].split('=', 2);
          if (kv[0] == param) {
             field.value = kv[1];
             return;
          }
       }
    }


$(function () {
    $("a.reply").click(function (e) {
       console.log("clicked");
       insertParamIntoField(this, "replyto", $("#inputField")[0]);
       e.preventDefault();
       return false; // prevent default action
    });
});

the html file

<textarea name="inputField" id="inputField" tabindex="1" rows="2" cols="40"></textarea>
    <a class ="reply"  href="home.php?replyto=username">reply</a>

this is my script what it deos it when the user clicks the reply link it prints @username, but i was wondering if i was at the button of the page and clicked reply, i want the focus to go back up on the textarea at the top? i was thinking along the lines of using #tags in html but is thier a way to do in jquery/javascript!! thanks

+2  A: 

You can call $("#inputField").focus().

Paul Schreiber
cheers thanks mate
getaway
Please accept the answer.
Paul Schreiber
accepted!!!!!!!!!
getaway
getaway
What do you mean?
Paul Schreiber
A: 

you can also use document.getElementById("inputField").focus()

PRS