I have a java application that talks via websocket with my javascript webinterface. The webinterface consists of basic form elements such as inputs, radio buttons, a jquery slider and so on. The form fields are monitored by the jQuery .on(change)-Function. If a form field changes by user input the on-change-function triggers the websocket-transmission of the changed-data.
Now there is following problem: If a user in a second instance triggers a change the Java-Server will broadcast the information to every client. Now I want that the form element gets refreshed by changing it's value. But this is impossible because the change will trigger the onchange-event again.
So it will be an endless loop. How to solve that? Is there any way to bypass the .on(change)-Function or do I have to change my design (If yes, how to change?)
Websocket-Snipped that gets fired when a other client has changed a value:
exampleSocket.onmessage = function (event) {
$('#freq11B').prop('checked',true);
};
jQuery Buttonset:
<div id="radioset">
<input type="radio" id="freq11A" name="freq"><label value="216.928" class="tooltip" for="freq11A">11A</label>
<input type="radio" id="freq11B" name="freq"><label value="218.640" class="tooltip" for="freq11B">11B</label>
<input type="radio" id="freq11C" name="freq"><label value="220.352" class="tooltip" for="freq11C">11C</label>
</div>
Send Data to the Server:
$('#radioset').on('change', function() {
var inputid = $('input[name="freq"]:checked', '#ventusform').attr("id");
//FREQUENCY: (value just below):
if(!(inputid == "freqCustom")){
var freqvalue = $('label[for='+inputid+']').attr("value");
}else{
var freqvalue = $('#customfreq').val();
}
console.log(freqvalue);
examplesocket.send($('#customfreq').val());
});
The value does change, but the form is not refreshed. Rory McCrossan (comment below) is right! Howto change the value with refreshing the form without firing the onchange-function again?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire