I've got a table w/ multiple columns of text boxes. Each checkbox has an onClick event that goes to a js function where I want to store the variables that I'm passing to the js function. The variables are a primary key, and a field and a value for that field. I want to store these variables as checkboxes are checked/unchecked, and get all the variables and their values back and update a db when a submit button is clicked.
Is just a normal js array the best way to do this? Does anyone have any examples?
Here's my onClick function so far:
Code:
function saveit(projectID,field){
//alert(projectID + " " + field " " + value);
if(document.getElementById(projectID).checked == false){
//stub to store values of checked check boxes
}
if(document.getElementById(projectID).checked == true){
//stub to store values of checked check boxes
}
}
Sure you could store them as an array, it all depends on what information you want to push out the db entry. If you want lists stored then use an array, otherwise a simple true/false is okay. Also not sure if you're trying this or not, but you'll need server side code to connect to the db, javascript alone won't get you all the way there.
In practice, I've found the easiest way to deal with checkboxes is to store the value of the checked elements as a comma deliminated string in a text field.
Then when re-rendering the page, use the preprocessor-appropriate string search function (VB: InStr, PHP: strpos) to find that value and print the "Checked='Checked'" string if found.
When it comes time to query the database, simply use a Count/Where LIKE '%,VALUE,%' combo to pull the value out of the string (just remember to pad the front and back of the string with commas)
actually, is there a way to get checkbox id's and values when the page loads, and then when I submit can I get all the id's and values again? That way I could compare arrays and only update values that have changed.
Bookmarks