Click to See Complete Forum and Search --> : populating form fields from arrays


idiotbear
07-21-2003, 06:15 AM
hi

I have an array called aTrusts , and I need to take values from this array and bung them into a form field, depending on the value of a combo box.

This is the function I'm using to do this, and I get an "object expected" error on it every time - I've tried everything and it's still wrong...

any ideas?

function setValues(sel)
{
val = sel.options[sel.selectedIndex].value;
x = 0;
for (i=0; i<aTrusts.length; i++)
{
if (aTrusts[i][0] == val) {
comp = aTrusts[i][10];
x = 1
}
}
if (x == 1)
{
document.forms[0].InvAddress.value = comp;
}
else {
alert ("Value not found");
}
}



The function is called by onchange="(setValues(this)" on the combo box.

SlankenOgen
07-21-2003, 06:50 AM
Can U post all html + code? There are many things that could be wrong.

idiotbear
07-21-2003, 06:59 AM
well, I'm sure u don't wanna see all 403 array rows lol, but here's the code with a couple of example rows

<Script language="JavaScript" type="text/javascript">
var aTrusts = new Array()
aTrusts[0] = new Array('recordID','addressLine1,'addressLine2','addressLine3','addressLine4','addressLine5','addressL ine6','postcode');
aTrusts[1] = new Array('recordID1','addressLine1,'addressLine2','addressLine3','addressLine4','addressLine5','address Line6','postcode');
function setValues(sel)
{
val = sel.options[sel.selectedIndex].value;
x = 0;
for (i=0; i<aTrusts.length; i++)
{
if (aTrusts[0] == val) {
comp = aTrusts[i][10];
x = 1
}
}
if (x == 1)
{
document.forms[0].InvAddress.value = comp;
}
else {
alert ("Value not found");
}
}


</script>


[I]And this is where the function is called:

<select name="trust" id="trust" onChange="setValues(this);">
<option value="R50418">135 Bishopsgate Limited&nbsp;(R50418)</option>

<option value="recordID">name</option>
<option value="recordID1">name1</option>
<option value="recordID2">name2</option>
etc
etc
</select>

Charles
07-21-2003, 07:11 AM
You still haven't given us enough information. Post the URL, please. In particular I would be interested to see if InvAddress really exists. And knowing what line is throwing the error would be helpful.

idiotbear
07-21-2003, 08:21 AM
InvAddress does exist.

But If you'd like to see the whole thing, here it is (please note, I have removed most of the array and option box values, as there are 403 rows of each, and they're not necessary to understand the page.

Here you go.


<html><Head>
<Script language="JavaScript" type="text/javascript">
var aClients = new Array()
aClients[0] = new Array('recordID','addressLine1,'addressLine2','addressLine3','addressLine4','addressLine5','addressL ine6','postcode');
aClients[1] = new Array ('recordID1','addressLine1,'addressLine2','addressLine3','addressLine4','addressLine5','addressLine6 ','postcode');
function setValues(sel)
{
val = sel.options[sel.selectedIndex].value;
x = 0;
for (i=0; i<aClients.length; i++)
{
if (aClients[i][0] == val) {
comp = aClients[i][10];
x = 1
}
}
if (x == 1)
{
document.forms[0].InvAddress.value = comp;
}
else {
alert ("Value not found");
}
}


</script>

<link href="css/styles.css" rel="stylesheet" type="text/css">
<title>Add a New Fee</title>
<body class="main" >
<table width="750" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="192" height="65"><img src="images/MainLogoCorp.jpg" width="192" height="55"></td>
<td width="558" align="right" valign="bottom">add a new fee</td>
</tr>
<tr>
<td height="20" colspan="2"><img src="images/divider.gif" width="750" height="10"></td>
</tr>
<tr>
<td height="20" colspan="2"><p><font size="2">Please enter the details of the new fee below.
All fields are required.</font></p>
<p><font size="2">When you have finished, click &quot;Add New&quot;. </font></p></td>
</tr>
</table>
<form action="regfee.asp" method="post" name="fees" id="fees" onSubmit="submitonce(this)">
<table width="750" border="1" cellpadding="2" cellspacing="4" bordercolor="#FFFFFF" class="main">
<tr>
<td width="18%" align="left" valign="middle">Client:</td>
<td colspan="3">
<select class="form" name="Client" id="Client" onChange="setValues(this);">
<option value="">Please Select</option>

<option value="recordID">name</option>
<option value="recordID1">name1</option>
<option value="recordID2">name2</option>
etc
etc
</select>
</td>
</tr>
<tr>
<td align="left" valign="middle">Account Number:</td>
<td colspan="3"><input class="form" name="account" type="text" id="account" size="10" ></td>
</tr>
<tr>
<td align="left" valign="middle">Currency:</td>
<td colspan="3"><select class="form" name="currency" id="currency" >
<option selected>Please Select...
<option value="&pound;">&pound; - Pounds
<option value="&euro;">&euro; - Euro
<option value="$">$ - Dollars
<option value="&yen;">&yen; - Yen
</select></td>
</tr>
<tr>
<td align="left" valign="middle">Frequency:</td>
<td colspan="3"><select class="form" name="feefrequency" id="feefrequency" >
<option value="" selected>Please Select...
<option value="1">Yearly
<option value="2">Half-Yearly
<option value="4">Quarterly
<option value="12">Monthly
</select></td>
</tr>
<tr>
<td align="left" valign="middle">Variable Fee?</td>
<td colspan="3"><input name="varFee" type="checkbox" id="varFee" value="checkbox"></td>
</tr>
<tr>
<td align="left" valign="middle">Total Annual Fee:</td>
<td colspan="3"><input name="amount" class="form" id="amount" size="30" >
<font size="1">numbers only</font></td>
</tr><tr>
<td align="left" valign="middle">Start Date:</td>
<td colspan="3"><input name="startdate" class="form" id="startdate" size="30">
<font size="1">dd/mm/yy</font></td>
</tr>
<tr align="left" valign="middle">
<td>VAT Rate:</td>
<td colspan="3"><select class="form" name="VAT" id="VAT">
<option selected> </option>
<option value="UK">UK
<option value="IRE">Ireland
</select></td>
</tr>
<tr align="left" valign="middle">
<td>Forward Invoice?</td>
<td colspan="3"><input name="FwdInvoice" type="checkbox" id="FwdInvoice" value="1" ></td>
</tr>
<tr align="left" valign="middle">
<td valign="top">Invoice Address:</td>
<td width="30%"><input name="InvAddress" type="text" class="form" id="InvAddress" size="30" >
<br>
<input name="InvAddress1" type="text" class="form" id="InvAddress1" size="30">
<br>
<input name="InvAddress2" type="text" class="form" id="InvAddress2" size="30">
<br>
<input name="InvAddress3" type="text" class="form" id="InvAddress3" size="30">
<br>
<input name="InvAddress4" type="text" class="form" id="InvAddress5" size="30">
<br>
<input name="InvAddress5" type="text" class="form" id="InvAddress6" size="30">
<br>
<input name="InvAddress6" type="text" class="form" id="InvAddress7" size="30">
<br>
<input name="InvAddress7" type="text" class="form" id="InvAddress8" size="30"></td>
<td id="fwdTD" width="12%" valign="top">Forwarding Address:</td>
<td width="40%" valign="top"><input name="FwdInvAddress" type="text" class="form" id="FwdInvAddress" size="30">
<br>
<input name="FwdInvAddress1" type="text" class="form" id="FwdInvAddress1" size="30">
<br>
<input name="FwdInvAddress2" type="text" class="form" id="FwdInvAddress2" size="30">
<br>
<input name="FwdInvAddress3" type="text" class="form" id="FwdInvAddress3" size="30">
<br>
<input name="FwdInvAddress4" type="text" class="form" id="FwdInvAddress4" size="30">
<br>
<input name="FwdInvAddress5" type="text" class="form" id="FwdInvAddress5" size="30">
<br>
<input name="FwdInvAddress6" type="text" class="form" id="FwdInvAddress6" size="30">
<br>
<input name="FwdInvAddress7" type="text" class="form" id="FwdInvAddress7" size="30"></td>
</tr>
<tr align="left" valign="middle">
<td>Debit Client Account?</td>
<td colspan="3"><input name="DebitTstAc" type="checkbox" id="DebitTstAc" value="1"></td>
</tr>
<tr>
<td align="left" valign="top">Comments:</td>
<td colspan="3"><textarea name="comments" cols="30" rows="4" class="form" id="comments"></textarea></td>
</tr>
<tr>
<td align="left" valign="top">Narrative:</td>
<td colspan="3"><textarea class="form" name="narrative" cols="30" rows="4" id="narrative" ></textarea></td>
</tr>
<tr align="left" valign="middle">
<td height="50"><h5>&nbsp;</h5></td>
<td height="50" colspan="3"> <input name="submit" type="submit" value="Add New">
<input name="reset" type="reset" value="Cancel"></td>
</tr>
<tr align="left" valign="middle">
<td height="50">&nbsp;</td>
<td height="50" colspan="3">&nbsp; </td>
</tr>
</table>
</form></body>
</html>

Charles
07-21-2003, 03:31 PM
You've dropped a couple of quote marks there but I cannot figure out how to trigger the problem that you described. And there is no "Add New" to click. I really think that it would be better if you just posted a url.

Vee
07-21-2003, 04:25 PM
I only to a quick glance but one question

comp = aClients[i][10];

When aClients only has 8 elements 0 to 7 in the second deminsion.