tsdragon, when I put quotes around the function call, it builds the textbox without firing the event, but it does not matter what event I use, it never gets fired off from that point.
I tried a global variable by setting it to true after the textbox is built, but that did not work either.
It seems that if I put quotes around it, it never fires the event. I tried onchange, onmouseout, onkeydown, etc. and the event is not being called.
Heres an example of the HTML calling the function:
<td><input type='button' onclick="javascript:addRow('myTable');" value='Add' <%=disabled%>></td>
Here's an example of the functions being used:
function addRow(id,oid)
{
var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0];
document.form1.sAction.value="";
<%ContactManager cMan = new ContactManager(); %>
var form = document.createElement("FORM");
form.name="addRowForm";
form.action='process_editReferences.jsp';
tbody.appendChild(form);
var row = document.createElement("TR")
var td0 = document.createElement("TD")
var td1 = document.createElement("TD")
var inp = document.createElement("INPUT");
inp.type='text';
inp.width='100';
inp.name='sCompanyName-' + index;
inp.value='';
td1.appendChild(inp);
td1.align='center';
var td2 = document.createElement("TD")
var inp2 = document.createElement("INPUT");
inp2.type='text';
inp2.width='100';
inp2.name='sName-'+ index;
inp2.value='';
td2.appendChild(inp2);
td2.align='center';
var td3 = document.createElement("TD")
var inp3 = document.createElement("INPUT");
inp3.type='text';
inp3.width='100';
inp3.name='sTitle-'+ index;
inp3.value='';
td3.appendChild(inp3);
td3.align='center';
var td4 = document.createElement("TD")
var inp4 = document.createElement("INPUT");
inp4.type='text';
inp4.width='100';
inp4.name='sPhoneNumber-'+ index;
inp4.value='';
td4.appendChild(inp4);
td4.align='center';
var td5 = document.createElement("TD");
var inp5 = document.createElement("INPUT");
inp5.type='text';
inp5.name='sEmailAddress-'+ index;
inp5.value='asdf';
inp5.width='100';
inp5.onchange='validateAddress(inp5.value)';
td5.appendChild(inp5);
td5.align='center';
row.appendChild(td0);
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
row.appendChild(td5);
tbody.appendChild(row);
index = index +1 ;
}
function validateAddress(incoming) {
var emailstring = incoming;
var ampIndex = emailstring.indexOf("@");
var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
// find a dot in the portion of the string after the ampersand only
var dotIndex = afterAmp.indexOf(".");
// determine dot position in entire string (not just after amp portion)
dotIndex = dotIndex + ampIndex + 1;
// afterAmp will be portion of string from ampersand to dot
afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
// afterDot will be portion of string from dot to end of string
var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
var beforeAmp = emailstring.substring(0,(ampIndex));
//old regex did not allow subdomains and dots in names
//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/
// index of -1 means "not found"
if ((emailstring.indexOf("@") != "-1") &&
(emailstring.length > 5) &&
(afterAmp.length > 0) &&
(beforeAmp.length > 1) &&
(afterDot.length > 1) &&
(email_regex.test(emailstring)) ) {
return true;
} else {
alert("Please enter a valid email address");
return false;
}
}