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
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?>';

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.