Question : Hide/show button depending of if textbox has text or not with jQuery?



Hi,

I have a a couple of datetime picker fields and if any of them is empty I want the Submit button to be invisible. I know how to do that but not how to make the button visible if all the datetime picker fields contains text.

I've seen exmaples using keyup but when I use the datetime picker I never put my cursor in the textbox and type something, the datetime picker populates the field.

The button has an ID ending with diidIOSaveItem. I can't use ID or name with the datetime pickers.

if ($("input[title='Target Date']").val().length < 1)
{
$("input[name$='diidIOSaveItem']").hide();
}
else
{
$("input[name$='diidIOSaveItem']").show();
}

This hides the button if there's no set target date. How do I show the button if there's something in the field no mater how I put it there?

Thanks in advance

Answer : Hide/show button depending of if textbox has text or not with jQuery?

You could re-purpose the checkControls function to return true or false, then call that in the PreSaveItem function.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function checkControls(){
					//the change event function - check the status of each control

					//set a variable to count the number of valid controls
					var controlsPassed = 0;

					//set up a selector to pick .each() of you target controls
					$("input[title=Target Date],input[title=Start Date],select[title=Strategic Objective],select[title=Strategic Priority]").each(function(){

							//if the control value is not zero AND is not zero-length
							if($(this).val() != 0 && $(this).val().length != 0) {

								//add one to the counter
								controlsPassed += 1
						}
					   });

					//call the showHide function and pass the true/false statement of 4 valid controls
					return (controlsPassed == 4);


				}


    function PreSaveItem() {
       return checkControls()
    }
Random Solutions  
 
programming4us programming4us