Welcome to WebmasterWorld Guest from 54.205.140.252

Forum Moderators: open

Message Too Old, No Replies

radio buttons

Ajax inside of Javascript

     
7:58 pm on Feb 16, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


I'm limited in my knowledge of Javascript and Ajax so bare with me.

I have a Javascript file that has a function in it. The function validates a form. At the end of that function is this:

  $.ajax({
type: "GET",
url: "thetargetedurl",
data: {
username: encodeURIComponent(username.value),
qq: encodeURIComponent(qq.value),
tel: encodeURIComponent(tel.value),
email: email.value,
product: question_1.value,
level: $("input[name='question_2']:checked").val(),
},

});


thetargetedurl has obviously been changed and the script works up to the last var being submitted: level. I can't get that to work.

Also. Once this submit is completed, I want the user to be taken to a thank you page (thankyou.php) but I can't get that to work either. I've tried using Javascript inside the function (window.location.href="thetarget"; and tried creating another function and then calling it at the end of this function. Still no go. Your help would be appreciated. TIA.
8:38 pm on Feb 16, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


What type of input element is 'question_2'? If it is a series of checkbox elements then you are going to get an array of values returned so you will need to choose the proper one from that array.
11:24 pm on Feb 16, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts: 7575
votes: 0


question 2 is a group of radio buttons
2:33 pm on Feb 17, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4988
votes: 12


You have a comma at the end of the line containing level, and also on the line following it. If you remove those 2 commas, does it work?


$.ajax({
type: "GET",
url: "thetargetedurl",
data: {
username: encodeURIComponent(username.value),
qq: encodeURIComponent(qq.value),
tel: encodeURIComponent(tel.value),
email: email.value,
product: question_1.value,
level: $("input[name='question_2']:checked").val()
}
});
9:05 pm on Feb 17, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


Thanks Fotiman, I'll check that out. I got the base code from online examples and they had the comma there which seemed odd but it worked for most of the variables. But I'll try it without the commas.