PDA

View Full Version : checkbox



unanet
July 4th, 2004, 05:32 PM
when i click on a submit button, it sends values to php. i have made 3 checkmoxes. when i select one and then click on a button, i want that the button transfer values that i selected. here is the code.

submit.onPress = function() {

if (checkbox1.value = true) {a1 != ""; a2 != ""; a1value != ""; a2value != "";

myData.a1value = a1value;
myData.a2value = a2value;
myData.sendAndLoad("savebar2.php", myData, "POST");
}

if (checkbox2.value = true) {a1 != ""; a2 != ""; a1value != ""; a2value != "";
myData.a1 = a1;
myData.a2 = a2;
myData.SendAndLoad("savebar2.php", myData, "POST");
}
checkbox1 = checkbox1.value;
checkbox2 = checkbox2.value;
checkbox3 = checkbox3.value;

myData = new LoadVars();
myData.onLoad = function() {
if (this.writing == "ok") {
status.text = "Datas are in the text";
} else {
status.text = "error";
}}
};

UN@

claudio
July 5th, 2004, 09:38 AM
You got a few of errors in your code.
Whenever comparing variables, use the == operator instead of the assignment operator (=);
You are defining the myData.a1 and myData.a2 properties even before first declaring the myData object, therefore they will have no value at all.
Also, i believe you're using sendAndLoad because you need to get a response from the PHP script. I don't know if it's necessary but i usually create another LoadVars object to receive that response. Something like this:


submit.onPress = function() {
myData = new LoadVars();
response = new LoadVars();
response.onLoad = function() {
if (this.writing == "ok") {
status.text = "Datas are in the text";
} else {
status.text = "error";
}
};
if (checkbox1.value == true) {
myData.a1value = a1value;
myData.a2value = a2value;
myData.sendAndLoad("savebar2.php", response, "POST");
}
};