Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange call 2 functions?

Status
Not open for further replies.

planeboy747

Technical User
Joined
Jan 11, 2005
Messages
41
Location
US
Is it possible for an onChange to call 2 functions at the same time?

Here's my onChange:
--------------------
<select name="select" onchange="adjustRows(this.value,nameSet)">

Here's my code for this script:
--------------------------------
function insertRows(isTable){
index = isTable.rows.length;
nextRow = isTable.insertRow(index);
isText1 = nextRow.insertCell(0);
isText2 = nextRow.insertCell(1);
index++;
index = index.toString();
nameStr1 = "Lname"+index;
nameStr2 = "Fname"+index;
txtStr1 = "Last Name "+index+":<br><input name="+nameStr1+" type='text' size='18' maxlength='18'>";
txtStr2 = "First Name "+index+":<br><input name="+nameStr2+" type='text' size='18' maxlength='22'>";
isText1.innerHTML = txtStr1;
isText2.innerHTML = txtStr2;
isText1.width ='25%'
isText2.width = '75%'
}

function adjustRows(isVal,isTable){

currRows = isTable.rows.length;
newRows = isVal;
if (currRows > 0){for (i=0; i<currRows-0; i++){isTable.deleteRow()}}
for (i=0; i<newRows; i++){insertRows(isTable)}
}


I'd like the function below with the same onChange above if possible, just not sure how you add this function to call on the onChange value?
--------------------------------
function insertRowsTN(isTable){

index = isTable.rows.length;
nextRow = isTable.insertRow(index);
isText1 = nextRow.insertCell(0);
index++;
index = index.toString();
nameStr1 = "TN1"+index;
txtStr1 = "Passenger 1 "+index+":<br><input name="+nameStr1+" type='text' size='18' maxlength='18'>";
isText1.innerHTML = txtStr1;
isText1.width ='25%'
}

function adjustRowsTN(isVal,isTable){

currRows = isTable.rows.length;
newRows = isVal;
if (currRows > 0){for (i=0; i<currRows-0; i++){isTable.deleteRow()}}
for (i=0; i<newRows; i++){insertRows(isTable)}
}

thanks
j
 
<select name="select" onchange="adjustRows(this.value,nameSet); adjustRowsTN(this.value,nameSet)">

It's not a good idea to use element tags, like select, text, option, textarea, as names for the elements.

Lee
 
Alternatively:
Code:
function adjustRowsTwo(pVal,pNameSet) {
   adjustRows(pVal,pNameSet);
   adjustRowsTN(pVal,pNameSet);
}
.
.
.
<select name="select" onchange="adjustRowsTwo(this.value,nameSet)">
This is my preferred method for several reasons:

It keeps the code in the html to an absolute minimum;

It's easier to maintain (in case you change one of the functions, add another function, etc.)

It's easier to read (no chance of overlooking the second function call in the onChange clause).


Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top