Jump to content

Help needed with simple Javascript array


ramone_johnny

Recommended Posts

Hey guys,

JS has never been my stronger point, so Im after a bit of help with this bit of code.

 

I have an auto suggest field that is populated by user input. When the user has made their final selection, they click on a button to "verify" this input.

 

In simple terms, here's what might be displayed in the auto suggest field upon user selection.

 

INALA, Queensland 4077;

 

...and then how its passed over to the verification popup window.

 

suburb=INALA%2C%20Queensland%204077%3B

 

I need to somehow split this up so I get each value separately.

 

eg

 

suburb - INALA

state - Queensland

pcode - 4077

 

Here's the existing snippet of JS that captures the user input.

 

var    suburb = fixField(form.search.value,0,"suburb");

 

Thanks!

 

If the user is allowed to enter in an arbitrary value, then there's no way to reliably split the data up into those values.  

 

If the validation window is ALWAYS passed a value in the exact format of

 

 

suburb=[suburb]%2C%20[state]%20[pcode]%3B

 

Then you can do something like this:

 

 

var suburb = "suburb=INALA%2C%20Queensland%204077%3B";
suburb = unescape(suburb).split(/=|,? |;/);

 

suburb will now be:

 

["suburb", "INALA", "Queensland", "4077", ""]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.