0

I use the following javascript code to validate/submit my form:

function SendForm()  {
            var formlist = document.getElementById ("formlist");
            var buttonRadios = document.getElementsByName ("film");
            var selected = false;
            for (var i = 0; i < formationRadios.length; i++) {
                if (formationRadios[i].checked) {
                    selected = true;
                    break;
                }
            }
            if (selected) {
                 document.formlist.submit ();

            }
            else {
           //nothing to do
            }            
        }

In the Html side:

<form  method="post" name="formlist"  action="films.php" OnChange="SendForm();">
...
<input type="radio" name="film" id="spman" value="spman" required="required"><label for="spman">Spider Man</label>
...

<select class="required" name="date" id="date">
<option selected value="13-05-2012">13 May 2012</option>
...
</select>
</form>

This works with firefox beta under android but not with the android default browser. It also works with firefox desktop browser.

Could you tell me what's wrong with it, I don't have errors inf firebug console.

Update:

I finally found the problem, it doesn't come from the code but from the iPhone/iPad bug with checking radio box when clicking label, for further information:

http://v4.thewatchmakerproject.com/blog/how-to-fix-the-broken-ipad-form-label-click-issue/

Thank you all for your help.

Zatla00
  • 419
  • 3
  • 17
  • 1
    Read this first: http://stackoverflow.com/questions/3957055/console-log-browser-in-android-emulator This will tell you how to debug Android Browser for javascript errors. If you get the error message, update your question then we'll try to help you further. – papaiatis May 30 '12 at 21:25

1 Answers1

0

Since Android 2.2 the built-in browser doesn't support the access of forms through the document object (Like document.name_of_your_form.submit()). Try one of the following possibilities:

id attribute:

HTML

<form id="formlist">

JavaScript

var formlist = document.getElementById("formlist");

name attribute

HTML

<form name="formlist">

JavaScript

var formlist = document.forms["formlist"];

or

var formlist = document.formlist;
chucktator
  • 1,828
  • 12
  • 16
  • 1
    I tried both solutions, they work fine on firefox on my desktop withour error, but in android default browser form is not sumbmitted :/ – Zatla00 May 30 '12 at 21:46
  • Are you doing this inside an android App (WebView)? Or just as a regular website. And a very stupid question: Is JavaScript maybe turned off on your Android device by any chance? – chucktator May 30 '12 at 21:50
  • Thanks, It is inside a website and javascript is enabled :/ I also activated console under via about:config method, I d'ont understand what is happening ! – Zatla00 May 30 '12 at 21:55
  • Well the `id` was definitely one problem and your original method of access doesn't Work since Android 2.2. Could you try putting an `alert()` in your `SendForm()` function and see if it shows up on Android? – chucktator May 30 '12 at 22:19
  • I added an alert msg in the SendForm() function Firefox mobile : ok Firefox Desktop : ok Android Built in browser: KO – Zatla00 May 31 '12 at 13:15
  • Then the Android browser doesn't support the `onchange` event for forms. I'm actually surprised that it works anywhere, as I've never heard of it before. Try setting up the events on your `input` fields. – chucktator May 31 '12 at 22:16