0

I am trying to adjust the code in this question for my needs. I need to extract the title attributes from selected elements and post them but my attempt at adjusting it is not quite working...

function submit(id) {
    var answers = document.getElementsByClassName("selected");
    var answersobject = {qid: id}
    for (var i = 0 ; i < answers.length ; i++){
        var j = i + 1;
        var ans = "a" + j;
        answersobject[ans] = answers[i].getAttribute['title'];
    }
    var loc = "testsub.php";
    $.redirectPost(loc, answersobject);
}

$.extend(
{
    redirectPost: function(location, args)
    {
        var form = '';
        $.each( args, function( key, value ) {
            form += '<input type="hidden" name="'+key+'" value="'+value+'">';
        });
        $('<form action="'+location+'" method="POST">'+form+'</form>').appendTo('body').submit();
    }
});

Currently it redirects but no data is being posted.

Community
  • 1
  • 1
SeanBallentine
  • 173
  • 1
  • 2
  • 8
  • Sorry, if you were looking at this just after i posted it, there was an extraneous line that i forgot to remove which might have been confusing. Gone now. – SeanBallentine Jun 30 '15 at 19:44
  • No, just redirects and the POST array has no values in the "a1" through "a"whatever spots. – SeanBallentine Jun 30 '15 at 19:48
  • UPDATE: I tried commenting out the redirect and just alerting out answersobject['a4'] in a specific example and its just not there, so the error is earlier than the redirect – SeanBallentine Jun 30 '15 at 19:59

0 Answers0