Building Single Row Database Forms with HTML - The disableButtons(selectedButtons) Function
(Page 5 of 5 )
Before I give you the code for this function, let me first describe a JavaScript feature that you may not be familiar with. When you call a JavaScript function, the called function develops an internal array. The first element ([0]) of this array holds the first argument of the parameter list of arguments received by the function, the second element of the array holds the second argument of the parameter list, the third element holds the third argument, and so on. The length of the array is the number of arguments in the parameter list. The length of the array depends on the number of arguments you send in the parameter list and this number depends on you.
I use this feature in this function - "disableButtons(selectedButtons).” The name of this array is “arguments.” This name is given by JavaScript and is the same for all JavaScript functions called. The array is internal to the function and you do not see its construction. To obtain its length, you type “arguments.length.” The “disableButtons(selectedButtons)” function is used to disable the selected button. The “selectedButtons” parameter simply represents the list of IDs of the buttons you want disabled. The list can be of any length. The code for the function is:
function disableButtons(selectedButtons)
{
for (i=0; i<arguments.length; i++)
{
document.getElementById(arguments[i]).disabled = true;
}
}
You do not access the IDs using “selectedButtons,” you access them using “arguments[i].”
The enableButtons(selectedButtons)
You use this function to enable selected buttons. The explanation is similar to the one above. The code is:
function enableButtons(selectedButtons)
{
for (i=0; i<arguments.length; i++)
{
document.getElementById(arguments[i]).disabled = false;
}
}
The clearControls() Function
This function is used to clear the text Input controls, NOT the values in the rows of the recordset. You achieve this by setting the value of a text Input element to “”. The code is:
function clearControls()
{
for (j=0;j<6;j++)
{
ID = "EI" + j; //forming the control ID
document.getElementById(ID).value = "";
}
}
These are common functions written by us to use.
We continue in the next part of the series.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |