A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearAJAX checkbox if statement - page 1
User InfoPosts
AJAX checkbox if statement#1
I(ve got a bunch of variables being pulled from form ID(s before being sent in a query string to a PHP. However, as one input is a checkbox I(m trying to get AJAX to set the variables value according to whether it(s checked or not. i.e..

	if (document.getElementById((bold().checked) { var bold = "true"; 
}
else { var bold = "false"; }


But, it doesn(t actually send anything to the PHP. I(m guessing syntax a lot of the time, so if anyone can correct I(d be most grateful.

posted date: 2009-04-15 03:18:00


Re: AJAX checkbox if statement#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-15 03:18:01


Re: AJAX checkbox if statement#3
can you show us the actual sending method?

posted date: 2009-04-15 03:23:00


Re: AJAX checkbox if statement#4
As long as you(ve given it a name it should be accessible as "on" or "off" in the backend e.g.var $checked = $_POST["checkboxname"] == "on";So your javascript is redundant.

posted date: 2009-04-15 03:29:00


Re: AJAX checkbox if statement#5
Firstly, instead of:var bold = "true";I think you(re actually looking for something like:document.getElementById((bold().value = "true";Secondly, if the checkbox is not checked nothing will be sent to the PHP script (unchecked checkboxes are not sent as part of a form submission).

posted date: 2009-04-15 03:34:00


Re: AJAX checkbox if statement#6
Ideally, this would the answer but it's being sent in a GET and the string literally just has bold=true or bold= and nothing there. I tried using isset() or empty()... neither would work. I think it needs to be sorted in the JS.

posted date: 2009-04-15 03:44:00


Re: AJAX checkbox if statement#7
Didn't work on that as I have to still declare the var afterwards. Secondly, normally that is the case but this is submitted by an ajaxFunction onChange of anything. So the value does seem to be submitted whatever the cirumstances.

posted date: 2009-04-15 03:50:00


Re: AJAX checkbox if statement#8
If that's the case then I agree with chosta... we need to see the sending code.

posted date: 2009-04-15 05:05:00


Re: AJAX checkbox if statement#9
Agree, if the checkbox isnt checked, nothing will be send with the form

posted date: 2009-04-15 05:23:00


Re: AJAX checkbox if statement#10
Can't you just do var $isBold = $_GET["bold"] == "true" then?

posted date: 2009-04-15 05:26:00


Re: AJAX checkbox if statement#11
Thanks very much, I've actually identified the 'ahem' problem... PHP side the variable was typo'd out. The proposed method I used in the question has worked. :/ Sorry to faff you around guys, thanks for the effort.

posted date: 2009-04-15 07:16:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.