ok, I have a form with checkboxes. I am trying to put the selected items into an array and then just simply go to the next page (an AJAX page within the same HTML doc using jquery mobile). I dont want the form to submit the values in the URL. using “return false” seemed to be working before but now it isnt!?:
[code=html]<form name=”form1″ onsubmit=”validateDrink(); return false”>
<input type=”checkbox” name =”drinks1″ value=”beer” id=”beer”/>
<label for=”beer”>Beer</label>
<input type=”checkbox” name =”drinks2″ value=”cider” id=”cider”/>
<label for=”cider”>Cider</label>
<input type=”checkbox” name =”drinks3″ value=”wine” id=”wine”/>
<label for=”wine”>Wine</label>
<input type=”checkbox” name =”drinks4″ value=”spirits” id=”spirits”/>
<label for=”spirits”>Spirits</label>
<input type=”checkbox” name =”drinks5″ value=”alcopop” id=”alcopop”/>
<label for=”alcopop”>Alcopop</label>
<input type=”checkbox” name =”drinks6″ value=”other” id=”other”/>
<label for=”other”>Other</label>
<input type=”submit” value=”Submit”/>
</form>
[CODE] <script type=”text/javascript”>
function validateDrink(){
var total=””
{
if(document.form1.drinks1.checked)
total +=document.form1.drinks1.value + ” ”
}
{
if(document.form1.drinks2.checked)
total +=document.form1.drinks2.value + ” ”
}
{
if(document.form1.drinks3.checked)
total +=document.form1.drinks3.value + ” ”
}
{
if(document.form1.drinks4.checked)
total +=document.form1.drinks4.value + ” ”
}
{
if(document.form1.drinks5.checked)
total +=document.form1.drinks5.value + ” ”
}
{
if(document.form1.drinks6.checked)
total +=document.form1.drinks6.value + ” ”
}
if(total==””){
alert(“Please select drinks”)
}
else
var drinksArray = total;
startstop();
increaseProgress();
_gaq.push([‘_trackEvent’, ‘Drink type’, ‘Q3. Drinks: ‘ +drinksArray, ”, ms]);
document.location=’#Q4’;
swreset();
startstop();
}
</script>
Is there a better way I should be doing this? Thank you