aeroswat Posted January 21, 2010 Share Posted January 21, 2010 So I have several forms that update a database automatically after each control on the form loses focus. For example You have 3 text boxes assigned to 3 fields in a database. If the user clicks inside one of the text boxes and enters something then tabs to the next text box it will update the field that is assigned to the previous text box. This form consists of 4 different controls, (text boxes, drop down boxes, check boxes and radio buttons). These are the two functions I currently have working with text boxes... function changeText(field,ctrl) { if(!update(field,ctrl.value)) { ctrl.value = vstr; } } function update(fInp, valu) { var sn = document.getElementById('ctrstudentnumber').value; var upd = 0; $('#errDiv').hide(); if(fInp.length != 0 && valu.length != 0){ $.ajax({ type: "POST", url: "updateregister-exec.php", data: "field="+fInp+"&val="+valu+"&sn="+sn+"", async: false, success: function(msg){ var msg=msg.substr(0,msg.search("#STOP#")); if(msg.length >0) { if(msg == 1) { $('#errDiv').show(); $('#errDiv').html("<h3><b>Database updated!</b></h3>"); $('#errDiv').fadeOut(4000); upd = 1; }else { $('#errDiv').show(); $('#errDiv').html("<h3><b>Error. Incorrect information entered!</b></h3>"); $('#errDiv').fadeOut(4000); } } } }); } else{ $('#errDiv').show(); $('#errDiv').html("<h3><b>Error. Incorrect information entered!<b><h3>"); $('#errDiv').fadeOut(4000); } return upd; } The code for the drop down box change is very similar with the exception that I use selected instead of value. All of my change functions use the same update function. I am not sure however, how to do the radio buttons. My setup is that I have 6 radio buttons where only one can be selected of course. I need the ability to update that database whenever I select one of them. There is a twist though. There is a text box that corresponds to these radio buttons. Only one should be filled at a time so you can either type a value in the text box or you can select a radio button. If you do one the value of the other should be cleared. My problem as far as the radio buttons is that I don't know what will happen if I tab to a radio button that the user does not select. What will the update function do in that case? What value will return if the radio button is not selected? Quote Link to comment https://forums.phpfreaks.com/topic/189309-not-sure-how-to-approach-this/ Share on other sites More sharing options...
aeroswat Posted January 21, 2010 Author Share Posted January 21, 2010 Ok so I've almost got it done. Now I gotta know how to make it so no radio buttons in a group of radio buttons is checked. We'll say that the id for one group of radio buttons is radios. I want to be able to have a code that removes the selection on the radio button that is checked. Quote Link to comment https://forums.phpfreaks.com/topic/189309-not-sure-how-to-approach-this/#findComment-999407 Share on other sites More sharing options...
aeroswat Posted January 21, 2010 Author Share Posted January 21, 2010 My group of radio buttons are called eyeLeft and this code does not work var ctrf="eyeLeft"; var radios = document.getElementById(ctrf); for(var i=0; i<radios.length; i++) { radios[i].checked == false; } Quote Link to comment https://forums.phpfreaks.com/topic/189309-not-sure-how-to-approach-this/#findComment-999437 Share on other sites More sharing options...
RichardRotterdam Posted January 22, 2010 Share Posted January 22, 2010 var radios = document.getElementById(ctrf); the document.getElementById function only returns one element and not an array of elements. What does your html look like for the group of radio buttons? Quote Link to comment https://forums.phpfreaks.com/topic/189309-not-sure-how-to-approach-this/#findComment-999870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.