Well i've managed to create some javascript to set the ICAO24 address input element, the javascript can hopefully be updated to set other form elements too.
But trying to submit the form using javascript kept telling me that the form had no submit() method.
After a little research i found this page:
http://stackoverflow.com/questions/833032/submit-is-not-a-function-in-javascript.
If a form's submit button is named 'submit' then the form's default javascript submit() method has been overwritten - the submit() method no longer exists.
The same logic applies to the reset button name and the javascript reset() method.
FYI this is the HTML form:
<form action="/" method="post">
<fieldset>
<legend> Aircraft database </legend>
<table width="100%" class="no">
<tbody><tr><td class="no">Registration: </td><td class="no"><input type="text" value="" name="reg"> </td><td class="no small">[e.g. D-AIHA or daiha]</td><td rowspan="4" class="no"> </td>
<td align="right" width="10%" rowspan="4" class="no">
</td></tr>
<tr><td class="no">Selcal: </td><td class="no"><input type="Text" value="" name="selcal"> </td><td class="no small">[e.g. AE-KQ or aekq]</td></tr>
<tr><td class="no">ICAO24 address: </td><td class="no"><input type="Text" value="" name="icao24"> </td><td class="no small">[Mode-S address, default hex, or <input type="radio" value="D" name="t">dec <input type="radio" value="O" name="t">oct <input type="radio" value="B" name="t">bin]</td></tr>
<tr><td class="no"> </td><td class="no"><input type="submit" value="submit" name="submit"> <input type="reset" value="reset" name="reset"> </td><td class="no small">... <a href="/nobots.php">no bots</a> ... </td></tr>
</tbody></table>
</fieldset>
</form>
And a link to the
Markup Validation Service.
And my javascript:
var elements=document.forms[0].getElementsByTagName('fieldset')[0].getElementsByTagName('input');
var element;
for(var i=0, j=elements.length; i<j; i++){
element=elements[i];
switch(element.name){
case 'reg':
break;
case 'selcal':
break;
case 'icao24':
element.value='AD1041';
console.log('icao24 set');
break;
}
}
// document.createElement('form').submit.call(document.forms[0]); // doesn't work!
You can see that "stealing another form instance's submit() method" does not work.
Actually, i've been testing this using desktop Firefox browser, maybe the WebView (being a webkit based browser) will behave differently, the submit
might work on a WebView.
I'll leave you to have a read and experiment.
Martin.