Jump to content

[SOLVED] Inserting Radio/Checkbox Values to DB


street9009

Recommended Posts

Hello all,

 

I followed a simple tutorial to get this working and it's working great, all except one problem. Let me explain.

 

I have a simple form that's a survey. Some questions consist of a Yes or No response. Others can have any number of 22 responses checked. I have each "group" of radio buttons or checkboxes named the same (q1, q2, etc.)

 

My insert function(s) look something like this:

 

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() 
{
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Please wait while your record is inserted into the database..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var surveyID = encodeURI(document.getElementById('surveyID').value);
var accountID= encodeURI(document.getElementById('accountnum').value);
var q1 = encodeURI(document.getElementById('q1').value);
var q2 = encodeURI(document.getElementById('q2').value);
var q3 = encodeURI(document.getElementById('q3').value);
var q4 = encodeURI(document.getElementById('q4').value);
var q5 = encodeURI(document.getElementById('q5').value);
var q6 = encodeURI(document.getElementById('q6').value);
var q7 = encodeURI(document.getElementById('q7').value);
var q8 = encodeURI(document.getElementById('q8').value);
var q8a = encodeURI(document.getElementById('q8a').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?surveyID='+surveyID+'&accountID=' +accountID+'&q1=' +q1+'&q2=' +q2+'&q3=' +q3+'&q4=' +q4+'&q5=' +q5+'&q6=' +q6+'&q7=' +q7+'&q8=' +q8+'&q8a=' +q8a+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}

function insertReply() 
{
if(http.readyState == 4)
{ 
	var response = http.responseText;
	// else if login is ok show a message: "Site added+ site URL".
	document.getElementById('insert_response').innerHTML = response;
}
}

 

The problem with this is it always picks up the first input named q1, q2, etc. no matter which are selected.

 

How should I fix this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.