Reputation: 1
I've been searching for an answer for why this isn't working for several hours, and I'm stumped.
Here's the script including the javascript and form involved.
<script language="Javascript" type="text/javascript">
function complete(init){
alert ("in function with " + init);
var aList = new Array(<?php echo $aList; ?>);
var iList = new Array(<?php echo $iList; ?>);
for (var i = 0; i < iList.length; i++){
if (init == iList[i]){
alert ("replacing " + init + " with " + aList[i]);
this.frmMain.txtAtty.value = aList[i];
}
}
}
</script>
<FORM METHOD="POST" NAME="frmMain" ACTION=<?php echo $_SERVER["PHP_SELF"]; ?>>
<table width="75%" align="center">
<tr>
<td width="25%" align="right">Name:</td>
<td>
<input type="text" name="txtSender" size="30" value=""/><span class="noteText"> Your Name</span>
</td>
</tr>
<tr>
<td width="25%" align="right">Attorney:</td>
<td>
<input type="text" name="txtAtty" size="30" value="" onblur = "complete(this.value)">
</td>
</tr>
The two PHP echo statements are the parameters for the Arrays. The complete(this.value) function is supposed to take a 3 letter code (in the iList array) and substitute it with a name. The alerts are in there for debugging purposes, but i don't get either alert when i run the page. Any ideas?
Upvotes: 0
Views: 1467
Reputation: 178094
this.frmMain is not defined anywhere
change
onblur = "complete(this.value)"
to
onblur = "complete(this)"
and use
function complete(field){
var init = field.value;
alert ("in function with " + init);
var aList = new Array(<?php echo $aList; ?>);
var iList = new Array(<?php echo $iList; ?>);
for (var i = 0; i < iList.length; i++){
if (init == iList[i]){
alert ("replacing " + init + " with " + aList[i]);
field.value = aList[i];
}
}
}
Upvotes: 1