Click to See Complete Forum and Search --> : 'object expected' error


lazzerous
11-13-2003, 01:17 PM
I have a js function call within an html select box

The function is supposed to populate part of an array with the selected value, and then populate a text box with all of the elements of the array..

I am receiving the error 'object expected' on the line the select box is on.

Any ideas? The related pieces of code are below...


<script language="javaScript">
<!--
var finalpart;

function updatePart(specnum)
{
alert('um...');
var val = document.aform.pb_option[specnum].options[selectedIndex].value;
finalpart[specnum] = val;
var toshow = "";
alert(finalpart.length);
var l;
for (l = 0; l < finalpart.length; l++)
{
toshow .= finalpart[l];
}
alert(toshow);
document.aform.showpart.value = toshow;
}
-->
</script>


<select name="pb_option[4]" onChange="updatePart('4')">
<option value='P'>P - Pin (Plug)
<option value='2'>2 - Socket (Receptacle)
</select>


Thanks in advance for your assistance.

-=Lazzerous=-

gil davis
11-13-2003, 01:50 PM
}
-->
</script>
Common mistake. You are not allowed to have HTML in a script unless it is a literal. Comment it out like this:
}
//-->
</script>

lazzerous
11-13-2003, 01:59 PM
I commented that line out and am still receiving the error - any other ideas?

Thaks,
-=Lazzerous=-

pyro
11-13-2003, 02:10 PM
There are a few errors. Even like this (below) it isn't exactly working properly. I'm assuming that something else is supposed to be filling the array finalpart.

<script language="javaScript">
<!--
finalpart = new Array(); //changed
function updatePart(specnum) {
alert('um...');
var val = document.aform.elements["pb_option["+specnum+"]"].options[document.aform.elements["pb_option["+specnum+"]"].selectedIndex].value; //chaged
finalpart[specnum] = val;
var toshow = "";
alert(finalpart.length);
var l;
for (l = 0; l < finalpart.length; l++) {
toshow += finalpart[l]; //changed ( .= needs to be += )
}
alert(toshow);
document.aform.showpart.value = toshow;
}
//-->
</script>

lazzerous
11-13-2003, 02:43 PM
I tried your suggestion to no avail, but it did inspire a new solution that does work:

<script language="javascript">
var finalpart = new Array();
finalpart[0] = "";
finalpart[1] = "";
finalpart[2] = "";
finalpart[3] = "";
finalpart[4] = "";
finalpart[5] = "";
finalpart[6] = "";
finalpart[7] = "";
finalpart[8] = "";
finalpart[9] = "";
finalpart[10] = "";
finalpart[11] = "";
finalpart[12] = "";
finalpart[13] = "";
finalpart[14] = "";
finalpart[15] = "";
finalpart[16] = "";
finalpart[17] = "";
finalpart[18] = "";
finalpart[19] = "";
finalpart[20] = "";

function updatePart(aform,slct,specnum) {
// insert yyy style markup
var toshow = "";
finalpart[specnum] = slct.value;

for (i = 0; i < finalpart.length; i++)
{
toshow += " "+finalpart[i];
}
aform.showpart.value = toshow;

aform.showpart.focus();
}
</script>


<form name="aform">
<input type="text" name="showpart" value="">
<br><br>
<select name="pb[3]" onChange="updatePart(this.form,this.options[this.selectedIndex],3)">
<option value='9'>9 -
<option value='15'>15
<option value='21'>21
<option value='25'>25
<option value='31'>31
<option value='37'>37
<option value='51'>51
</select>


Thanks for all of the help!!!

pyro
11-13-2003, 02:57 PM
I said that what I posted would not work correctly, as the array would not be filled... I was assuming that you were filling it somewhere else, or I didn't think you'd use an array at all.