1

IMAGE OF FORM

HTML:

<select name="birthdate[day]" id="birthdate-day" class="date_class">
    <option value="0"> </option>
     .....
</select>
<select name="birthdate[month]" id="birthdate-month" class="date_class">
    <option value="0"></option>
    ..........
</select>
<select name="birthdate[year]" id="birthdate-year" class="date_class">
    <option value="0"> </option>
    <option value="2015">2015</option>
     ....
</select>

I tried to get data this way, but it didn't works:

var birthdate = $contactForm.getElement('select[name="birthdate"]').getProperty('value');

How to get array from form in JS or Mootools to send it than to PHP? Will be send data to PHP in JSON format.

3
  • possible duplicate of Convert form data to JS object with jQuery Commented Apr 23, 2015 at 16:39
  • @copeg need mootools Commented Apr 23, 2015 at 16:41
  • Do you want the selected value of that select element`or a array with all selected values of the form's selects? Commented Apr 23, 2015 at 19:26

1 Answer 1

1

The problem is with your selector. You are giving a partial name, but with the syntax you are using it expects the complete name.

So try something like:

var birthdate = $contactForm.getElement('select[name^="birthdate"]').getProperty('value');

However this is only going to get you the first element that matches.

So with MooTools, you could do something like:

$$('select[name^=birthdate]')

Or in JS:

document.querySelectorAll('select[name^=birthdate]')

Hope that helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.