В дополнение к тому, что предлагает Фуджи, есть несколько вещей, которые я заметил в вашей функции insertParamIntoField
:
// url: home.php?replyto=username, param: replyto, field: $("input .inputField")[0]
function insertParamIntoField(url, param, field) {
var anchor = document.createElement('a'), query;
// anchor is a link element and doesn't have a 'value' attribute
anchor.value = url;
// It also won't have a 'query' attribute. This probably causes an error
query = anchor.query.split('&');
// As stated above there is no 'query' attribute to split on, but
// also there are no &'s to split on in the url you pass in anyway.
// At best, query will equal the full url...
for(var i = 0, kv; i < query.length; i++) {
kv = query[i].split('=', 2);
// ...so splitting on = would get you
// query[0] = "home.php?replyto", query[1] = "username"
// ... and "home.php?replyto" != "replyto", so...
if (kv[0] == param) {
//... it never gets here. Also 'field' is a textarea, not an input
// so it also doesn't have a 'value' attribute. try field.html(kv[1]) istead
field.value = kv[1];
return;
}
}
}
Попробуйте это:
function insertParamIntoField(url, param, field) {
var qs = url.split("?");
var query = qs[1].split("&");
for(var i = 0, kv; i < query.length; i++) {
kv = query[i].split('=', 2);
if (kv[0] == param) {
field.html(kv[1]);
return;
}
}
}
$("a.reply").click(function () {
insertParamIntoField(this.href, "replyto", $("textarea#inputField"));
return false; // prevent default action
});