non si ha realmente bisogno di una o di un attributo method
action
se siete semplicemente utilizzando i campi di testo in Javascript
Aggiungi un pulsante submit
ed un onsubmit
gestore per la forma in questo modo,
<form name="testform" onsubmit="return processForm(this)">
<input type="text" name="testfield1"/>
<input type="text" name="testfield2"/>
<input type="submit"/>
</form>
poi, nel tuo Javascript si potrebbe avere questa funzione processForm
function processForm(form) {
var inputs = form.getElementsByTagName("input");
// parse text field values into an object
var textValues = {};
for(var x = 0; x < inputs.length; x++) {
if(inputs[x].type != "text") {
// ignore anything which is NOT a text field
continue;
}
textValues[inputs[x].name] = inputs[x].value;
}
// textValues['testfield1'] contains value of first input
// textValues['testfield2'] contains value of second input
return false; // this causes form to NOT 'refresh' the page
}
Nota come i controlli a esempio del PO non hanno un ID però ... –
Vero. OP dovrà aggiungere un ID ai suoi controlli di input. – Lowkase
Il mio punto è: non necessariamente. Usare un nome va bene, e poiché gli elementi del form hanno bisogno di un nome comunque (almeno quando comunicano anche tramite il modulo con un server), perché non usarlo? –