How can I compact this JS?

Hello,

How can I compact this code?

var the_month_selected;
if (window.document.registration_form.the_month_field.options[1].selected == true)
{
//alert(“It’s January!”);
the_month_selected = “01”
}
else
if (window.document.registration_form.the_month_field.options[2].selected == true)
{
//alert(“It’s February!”);
the_month_selected = “02”
}
else
if (window.document.registration_form.the_month_field.options[3].selected == true)
{
//alert(“It’s March!”);
the_month_selected = “03”
}
else
if (window.document.registration_form.the_month_field.options[4].selected == true)
{
//alert(“It’s April!”);
the_month_selected = “04”
}
else
if (window.document.registration_form.the_month_field.options[5].selected == true)
{
//alert(“It’s May!”);
the_month_selected = “05”
}
else
if (window.document.registration_form.the_month_field.options[6].selected == true)
{
//alert(“It’s June!”);
the_month_selected = “06”
}
else
if (window.document.registration_form.the_month_field.options[7].selected == true)
{
//alert(“It’s July!”);
the_month_selected = “07”
}
else
if (window.document.registration_form.the_month_field.options[8].selected == true)
{
//alert(“It’s August!”);
the_month_selected = “08”
}
else
if (window.document.registration_form.the_month_field.options[9].selected == true)
{
//alert(“It’s September!”);
the_month_selected = “09”
}
else
if (window.document.registration_form.the_month_field.options[10].selected == true)
{
//alert(“It’s October!”);
the_month_selected = “10”
}
else
if (window.document.registration_form.the_month_field.options[11].selected == true)
{
//alert(“It’s November!”);
the_month_selected = “11”
}
else
if (window.document.registration_form.the_month_field.options[12].selected == true)
{
//alert(“It’s December!”);
the_month_selected = “12”
}

Thanks

Lennox

Use an array instead.

Is this for a Xojo Web project?

Hi Greg,

I have a html form that will allow users to fill in the form on a tablet, (e.g. iPad)

I do not want to send the data via email or over the internet.

I am aware that HTML and Javascript cannot write to disk.

What I would like to do, until Xojo supports iOS, is to put the data in an encrypted state, (it does not have to be in a very secure way, base64 or Hex, or anything like that, is quite OK), in a text area then manually copy that data to a text file and save it on the tablet.

The text file can then be transferred to a desktop or laptop for processing in my Xojo built app.

I am trying to build this form to work with my Xojo app. I am new to JS and HTML.

Lennox

Ah okay.

So you could do this with a loop.

var i; for(i=1;i<=12;i++) { if(window.document.registration_form.the_month_field.options[i].selected) { the_month_selected = i; break; } }

Thanks Greg.
Lennox