sto cercando di verificare il contenuto di un modulo prima di inviarlo. Fondamentalmente, sto cercando di lavorare con i numeri nel modulo e assicurarmi che rientrino nell'intervallo corretto. Il problema è che il codice JavaScript che sto provando a verificare pensa che l'elemento che gli viene passato sia NaN (l'ho analizzato).Passaggio di una variabile modulo nel campo onsubmit?
Un po 'di lavoro ha rivelato che la variabile ("dimensione") si riferisce ad un "HTMLInputEleMent", che credo sia, in effetti, NaN (anche se io non sono abbastanza sicuro che cosa è in realtà). Credo che il problema è che l'onSubmit non passa quello che voglio che sia di passaggio, anche se ho chiamato il campo "dimensione" e ho passato onSubmit "dimensioni" troppo.
Ho provato a mettere tra virgolette, ma che appena lo trasforma in una stringa ...
mi chiedo se forse non si riesce a passare una variabile all'interno del modulo al suo campo onSubmit? È così? Se è così, come dovrei farlo?
Qui è la forma:
<form onsubmit="return goodForm(size, day, month, year)" action="http://localhost:8080/pomper_servlet/CostCalc" method="GET">
The day of the month must be entered as a number (ex: 1,22)
<input type="text" name="day"><br>
The month of the year must be entered as a number (ex: Jan.=1, etc.)
<input type="text" name="month"><br>
The year must be entered as a 4 digit number (ex: 2008, 2017)
<input type="text" name="year"><br>
Please Choose a tour-length, in accordance with the chart below:
<input type="TEXT" name="length"><br>
How many people will be in your group? (No More than 10 allowed!)
<input type="text" name="size"><br>
Please select a tour:<br>
<input type="RADIO" name="tour" value="Gardiner Lake">
Gardiner Lake<br>
<input type="RADIO" name="tour" value="Hellroaring Plateau">
Hellroaring Plateau<br>
<input type="RADIO" name="tour" value="The Beaten Path">
The Beaten Path<br>
<input type="SUBMIT" value="Submit">
</form>
E qui è la funzione, da functions.js:
function goodForm(gSize, day, month, year) {
"use strict";
window.alert("goodFrame(): "+gSize);
var groupSize1 = parseInt(gSize.replace(/^"|"$/g, ""), 10);
window.alert("goodFrame(): "+groupSize1);
var sizeInt = parseInt(groupSize1);
if(groupSize(sizeInt) && goodDate(day, month, year)){
window.alert("true");
return true;
}
else{
window.alert("false")
return false;
}
Non ci sono riferimenti ad altre funzioni in là, ma non sono rilevanti per questo, penso. Gli avvisi sono stati/sono solo a scopo di debug ...
Grazie in anticipo!
Puoi cercare il campo per ID all'interno del metodo onsubmit? – oooyaya
Ehm ... forse - come faccio a farlo (sono abbastanza nuovo a questo, nel caso in cui non sia ancora chiaro ...) –
Vedere la risposta qui sotto. Elaborerò. – oooyaya