poll with ajax support.limited number of choices

linderox

New Member
I have to make a poll with many checkbox'es. I want to use php with AJAX for my purpose.
1)Is it possible to limit number of user choices with the helps of AJAX?I want to accept only 3 choices. how to do that?

2)Is it possible to get order of choices and how? - It's important for me know in which order user choose items of the poll
 

jnjc

New Member
You would probably be better using javascript to achieve both of these requirements.

1) Using JS to see how many boxes are checked would be easier then trying to do this using ajax.

2) This could be a tricky one as what happens if the user checks a box unchecks it, checks some more boxes and checks it again ? As far as I can see you have to do this client side and JS would be your best bet. Your simplest way to do it would be to have a 'value-changed' trigger that adds the ID of the select box onto a string, then send the string back with the Ajax call.

Something like:

HTML:
Code:
	<input onclick="TrackChange(this);" type="checkbox" id="test1" value="">
	<input type="hidden" id="Tracker" value="">

Javascript:

Code:
function TrackChange(oField) {
 var action ="u";  
 if (oField.checked) action = "c";
 action = action + oField.id;	
 document.getElementById("Tracker").value  =
    document.getElementById("Tracker").value + action + ",";
}

The value of 'Tracker' will have a list of field Id's with a prefix C if they where checked and u if unchecked. You could then use server side code to make sense of the values.

HTH,
JC
 

linderox

New Member
thank you... now I have to find a good book about AJAX and java script or maybe a good example. what about the last one?
 
Top