1
On my page is a form where the user chooses a numerical value. I want that whenever the user changes the value, the form is sent, without the need to press the "send".
The code I tried, but it didn’t work:
var valor = document.txtForm.valor.value;
var valorant = document.txtForm.valor.value;
while(1){
valor = document.txtForm.valor.value;
if(valor != valorant){
document.valor_analog.submit();
}
valorant = document.txtForm.valor.value;
}
<html>
<body>
<script src="env_aut.js"></script>
<form name ="valor_analog" action="http://192.168.0.3/" method="POST">
<input name="valor" type="range" min="100" max="500" step="10" />
<input type="submit" value="Submit">
</form>
</body>
</html>
I’m using the following code now.
function envia(){
$.post("http://192.168.0.3/",{valor: $("#valor").val()},function(){});
}
<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<form id="valor_analog" action="http://192.168.0.3/" method="POST">
<input name="valor" id="valor" type="range" min="100" max="500" step="10" oninput="envia()"/>
<input type="submit" value="Submit">
</form>
</body>
</html>
The only problem is it’s taking too long.
You’ll have to own the property
onchange
in your input pointing to a function, which so each time the value is changed goes to a given function, and within that function you use Ajax to submit the form– CesarMiguel
Thanks. I took a look and the event "oninput" sends in real time, while "onchange" only sends after you release the mouse. But it helped.
– Carlos