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!

 

Link to comment
Share on other sites

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", ""]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.