views:

26

answers:

2
<html>
<head>

    <script type="text/javascript"

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;

<script type="text/javascript">

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.val(kv[1]);

             return;
          }
       }
    }


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

</script>
</head>
<body>
<textarea></textarea>
<a class="reply" href="?replyto=you">TEST</a>
</body>
</html>

what im trying to is when i click the link, the replyto parameter is inserted into the textarea, in this example "you"it was working 2 days ago! i dnt know whats wrong

+1  A: 

Edit: I falsely assumed you were using firebug, from comments I see you weren't and that installing it resolved your issue. This line:

console.log("clicked");

Will blow up if firebug isn't installed and always in IE, when testing in an environment without a console, be sure to remove any calls to it...it'll throw a JavaScript error otherwise.

Nick Craver
thanks for answering, i just checked your test page, and its not wokring for me, is thier something wrong with my browser, becuase javascript is enabled
getaway
Should not matter at all.
BGerrissen
@getaway - Do you have a link? something outside the scope of the question is affecting it, since what you posted works.
Nick Craver
@BGerrissen - IE can have issues here, not that anyone's surprised by this :)
Nick Craver
no im running on my localhost!!! at the momment
getaway
If he's testing in IE, it's more likely that console.log() is breaking the code ;)
BGerrissen
its not working for me on IE aswell
getaway
@getaway - As BGerrissen said, `console` isn't in IE and it'll break it too, even if the rest works...are you getting any errors in your firebug console? If you don't have firebug, install it :) http://getfirebug.com/
Nick Craver
i just installed firebug, and i clicked on console and then it works, but then when i close firebug it deost work again
getaway
@getaway - Without firebug, `console.log()` doesn't work, you need to remove any `console` statements when not testing in an environment with it (this includes IE).
Nick Craver
what the f== im so confused
getaway
@getaway - `console` is the firebug console...it's not an object in JavaScript unless it's installed/running, it's not something just there by default, at least in Firefox :)
Nick Craver
okay kool, so basically when i put my website in production i need to take off the console.log from my script!
getaway
@getaway - yes! definitely :)
Nick Craver
@nick, your a star, i just leanred something new, one upvote for you!!!
getaway
A: 

Is your internet connection working ok? You're using jQuery from google API, so what happens if you reference a local version?

Also, what happens when you click: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?

James Wiseman
i clciked the code it shows the jquery code from google
getaway