I am trying to pass a user name and password through a dynamically created form but it's not doing so. Here's the JS. The dynamically created form is only if the url contains certain url stems ( location.pathname...3rd "if" statement) Any ideas? It's driving me crazy.
function PostToAccountManagement() {
var userName = $('#Username').val();
var passWord = $('#Password').val();
if (userName == "")
$('#UsernameError').html('Please enter a valid username');
else
$('#UsernameError').html('');
if (passWord == "")
$('#PasswordError').html('Please enter a valid password');
else
$('#PasswordError').html('');
if (location.pathname.search(/\/info/i) == 0 ||
location.pathname.search(/\/blogs/i) == 0 ||
location.pathname.search(/\/groups/i) == 0 ||
location.pathname.search(/\/askquestion/i) == 0) {
$('<form id="Form1"> </form>').prependTo('body');
if (userName != "" && passWord != "") {
开发者_Go百科 document.cookie = "ReturnUrl" + "=" + window.location.href;
$('#Form1').eq(0).attr('action', '/account/logon');
$('#Form1').eq(0).attr('method', 'post');
$('#Form1').submit();
}
}
if (userName != "" && passWord != "") {
document.cookie = "ReturnUrl" + "=" + window.location.href;
$('#Form1').eq(0).attr('action', '/account/logon');
$('#Form1').eq(0).attr('method', 'post');
$('#Form1').submit();
}
}
First the form you creates in the 3rd "if". Looks like you already have a form with id "Form1", this is not good.
Second you can't get the username and password when the 3rd "if" is triggered because the form you submit don't have elements named like that, it actually have none. Try adding at least some hidden inputs properly named.
精彩评论