View Full Version : Can somebody look at this, I'm baffled

04-09-2009, 09:25 AM
I am not an expert with Javascript but I have managed to resolve the majority of my problems in trying to retrieve a detailed string from an array using a part of that string as the search parameter.

The thing that I can't resolve is why I can't get it to work as a single function by joining together the 2 functions I have created.

Here is my code, after the array drirejs has been created by PHP and converted to a JS array:

<script type="text/javascript">

var rand = new Array();
var john = new Array();

function test_example(){
for (j = 0; j <= drirejs.length; j++) {
john [j]= title;

function testindex(drire_search){
var srchstr=drire_search;

if (!Array.prototype.indexOf)
Array.prototype.indexOf = function(elt /*, from*/)
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;

for (; from < len; from++)
if (from in this &&
this[from] === elt)
return from;
return -1;


<td width="12%" height="123"><script>test_example();</script></td>
<td width="12%" height="123"><script>testindex("LORRAINE - Vosges(88)");</script></td>

When the 2 functions are called separately, and consecutively, I get the right result in the alert() from the testindex function.

When I join the 2 functions I don't even get the alert.

In desperation I have tried to call the 2 functions from another, eg. function xyz(){test_example();testindex(str);}, but this doesn't work either.

I need this to be a single function because I want to call it from a SELECT field on a form.

This might be something simple and stupid that I've overlooked but I have tried and tried and can't find the solution.

Hoping one of you JS experts can help me on this