Jump to content

[SOLVED] Passing Checkbox Value Issue


mcmuney

Recommended Posts

I have a form that utilizes javascript to pass the form data, to which, I'm trying to add a checkbox. But regardless if the box is checked or not, the same value "Y" is being passed. What do I need to do so it differentiates if the box is checked or not???

 

Javascript Portion

function sub(frm)
			{
				if(frm.txt_comment.value=="")
				{
					alert("Did you forget to enter your comment?");
					return false;
				}
				else
				{
					var comment_text=frm.txt_comment.value.escapeHTML();

					comment_text = comment_text.replace(/\//g,"%2F");
     				comment_text = comment_text.replace(/\?/g,"%3F");
     				comment_text = comment_text.replace(/=/g,"%3D");
     				comment_text = comment_text.replace(/&/g,"%26");
     				comment_text = comment_text.replace(/@/g,"%40");
     				
					frm.hinsert.value='True';
					frm.sci_id.value=<?=$sci_id?>;
					//frm.submit();
					var pars = "txt_comment="+comment_text+"&txt_anon="+frm.txt_anon.value+"&sci_id="+frm.sci_id.value+"&hinsert="+frm.hinsert.value+'&update='+frm.update.value+
								'&scm_mem_id=<?=$scm_mem_id?>';
					new Ajax.Updater({success:'silentPost'},'code/Ajax_comment_posting/postPictureComment.php',
						{method: 'post', parameters: pars, onLoading:onStartPosting, evalScripts:true, onFailure:onPostingFailed});
				}
			}

 

This is the checkbox that I'm trying to add

<input type="checkbox" name="txt_anon" value="Y">

Link to comment
https://forums.phpfreaks.com/topic/147888-solved-passing-checkbox-value-issue/
Share on other sites

the value will always be the same. you need to check to see if "checked" is true.

var pars = "txt_comment="+comment_text;
if(frm.txt_anon.checked)
  pars += '&txt_anon='+frm.txt_anon.value;
pars += '&sci_id='+frm.sci_id.value+'&hinsert='+frm.hinsert.value+'&update='+frm.update.value+'&scm_mem_id=<?=$scm_mem_id?>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.