/    Sign up×
Community /Pin to ProfileBookmark

how to NOT send form values as variables in URL

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]

[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>[/CODE]

Is there a better way I should be doing this? Thank you

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 26.2011 — There must be an error somewhere within the other functions. This can explain why the return false is not fired: the code breaks, due an error, somewhere else.
×

Success!

Help @sjjs1985 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...