I have a form that allows multiple checkbox. I want to get a random value of all checked items when the "Generate" button is pressed.
On the one hand I have the form:
<FORM NAME="testform">
<INPUT CLASS="cities" TYPE="checkbox" NAME="mex" Value="mex"checked="checked">México<BR>
<p><INPUT CLASS="cities" TYPE="checkbox" NAME="ita" Value="ita">Italy<BR>
<p><INPUT CLASS="cities" TYPE="checkbox" NAME="usa" Value="usa">United State of America<BR>
<p><INPUT TYPE="button" NAME="button" Value="Generate"
onClick="testButton"><BR>
</FORM>
But I am a novice in JavaScript and I need help building this exercise.
By the other hand I have no idea how to get the form values. These are the random elements of each checkbox.
var mex=["mexico-df.html","veracruz.html","acapulco.html"]
var ita=["roma.html","milan.html","venecia.html"]
var usa=["los-angeles.html","new-york.html","washington.html"]
I want that if something check México and USA, for example, the result should be only one random value between those included in the above variables.
I do not know exactly how to get the checked values from the form and how to pick a random value from only selected items.
Do you have any suggestions for me?
Sorry if my English is not so good.
Aucun commentaire:
Enregistrer un commentaire