Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/189309-not-sure-how-to-approach-this/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.