Using checkboxes can become a pain when you want to get a default value for them, usually when they are not checked, because an unchecked checkbox will not be sent to the processing script regardless if it’s sent via POST or GET. The easiest way to deal with this, not using JavaScript is to use another input field , hidden, with the same name, that will hold a default value. So if the checkbox is unchecked the value from the hidden field will be sent, otherwise the value from the checkbox will overwrite the value from the hidden field.
<input type="hidden" name="custom_criteria_influence" value="0" /> <input type="checkbox" name="custom_criteria_influence" value="1" />
This looks like a great solution for “static” forms, but if we have dynamically added fields that will be stored in an array, there’s also a nice workaround, using the same principle.
Using this code to add new custom fields into a form:
var cfields = 0; $( '#add-custom-criteria' ).click( function() { var field_name = $( '#custom-criteria-name' ).val(); if( field_name.length ) { $('.custom-criteries-added' ).append('<p class="form-row big-label">' +'<input type="checkbox" name="custom_criteria_do[]" checked value="' + field_name + '" class="do-class fl margin-right-5" />' +'<label>' + field_name + '</label>' +'<input type="text" name="custom_criteria_value[]" value="0" size="2" /> % prag acceptat ' +'<input size="3" name="criteria_max[]" type="text" /><input type="hidden" name="custom_criteria_title[]" value="' + field_name +'" />' +'<br><span>Criteriul este avantajos la valori mari.</span> +'<input type="hidden" name="custom_criteria_influence['+cfields+']" id="" value="0" />' +'<input type="checkbox" name="custom_criteria_influence['+cfields+']" id="" value="1" checked="checked" />' +'</p>'); $( '#custom-criteria-name' ).val( '' ); } cfields++; return false; });
we can generate something like this:
<div class="custom-criteries-added"> <p class="form-row big-label"> <input type="checkbox" name="custom_criteria_do[]" checked="" value="First field" class="do-class fl margin-right-5"> <label>First field</label><input type="text" name="custom_criteria_value[]" value="0" size="2"> % prag acceptat <input size="3" name="criteria_max[]" type="text"> <input type="hidden" name="custom_criteria_title[]" value="First field"><br> <span>Criteriul este avantajos la valori mari.</span> <input type="hidden" name="custom_criteria_influence[0]" id="" value="0"> <input type="checkbox" name="custom_criteria_influence[0]" id="" value="1" checked="checked"> </p> <p class="form-row big-label"> <input type="checkbox" name="custom_criteria_do[]" checked="" value="Second field" class="do-class fl margin-right-5"> <label>Second field</label><input type="text" name="custom_criteria_value[]" value="0" size="2"> % prag acceptat <input size="3" name="criteria_max[]" type="text"> <input type="hidden" name="custom_criteria_title[]" value="Second field"><br> <span>Criteriul este avantajos la valori mari.</span> <input type="hidden" name="custom_criteria_influence[1]" id="" value="0"> <input type="checkbox" name="custom_criteria_influence[1]" id="" value="1" checked="checked"> </p> </div>
The fields that I needed to get a default value from, are custom_criteria_influence[], and defining a key for each pair of fields (checkbox, hidden) will help me get the values (default values) for the checkboxes that are not checked, so I can add them into database.
Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.