How To Search Through Array Looking For Inputted Entry

Mar 9, 2010

How do I search through an array looking for an inputted entry? Ihave this so far. Also need it to display where the object was found.
var states = new Array();
var i;
i=0;

states[0] = "Alabama";
states[1] = "Alaska";
states[2] = "Arizona";
states[3] = "Arkansas";
states[4] = "California";
states[5] = "Colorado";
states[6] = "Connecticut";
states[7] = "Delaware";
states[8] = "Florida";
states[9] = "Georgia";
states[10] = "Hawaii";
states[11] = "Idaho";
states[12] = "Illinois";
states[13] = "Indiana";
states[14] = "Iowa";
states[15] = "Kansas";
states[16] = "Kentucky";
states[17] = "Louisiana";
states[18] = "Maine";
states[19] = "Maryland";
states[20] = "Massachusetts";
states[21] = "Michigan";
states[22] = "Minnesota";
states[23] = "Mississippi";
states[24] = "Missouri";
states[25] = "Montana";
states[26] = "Nebraska";
states[27] = "Nevada";
states[28] = "New Hampshire";
states[29] = "New Jersey";
states[30] = "New Mexico";
states[31] = "New York";
states[32] = "North Carolina";
states[33] = "North Dakota";
states[34] = "Ohio";
states[35] = "Oklahoma";
states[36] = "Oregon";
states[37] = "Pennsylvania";
states[38] = "Rhode Island";
states[39] = "South Carolina";
states[40] = "South Dakota";
states[41] = "Tennessee";
states[42] = "Texas";
states[43] = "Utah";
states[44] = "Vermont";
states[45] = "Virginia";
states[46] = "Washington";
states[47] = "West Virginia";
states[48] = "Wisconsin";
states[49] = "Wyoming";

View 2 Replies


ADVERTISEMENT

Append Text To End Of Search Entry

Dec 1, 2010

My work website, [URL] has an activity search on the top-right side of the page that searches congregation details. It mostly works fine, except that if you search "greenwood" instead of getting shown Greenwood Uniting Church, it tells you that there are no congregations within 15km of Greenwood. Yet if you search "Kingsley" (Next suburb over, less than 15km from Greenwood) it finds the Greenwood Uniting Church.

We worked out that the issue is that there is more than one Greenwood in Australia, so it needs to be clarified that the state of WA needs to be added to the search. The easiest way (I feel) is to check whether WA has been included in the text, and if not, to add it to the search text. This is the code I've got so far (written by a friend, who wasn't certain whether it would work or not):

PHP Code:
echo '<script type="text/javascript">';
// Check that there's state appended to the search
echo 'function checkState(){';
echo 'var searchField=document.getElementById("suburb-address");';
echo 'if (searchField.value.lastindexOf("WA")==0) { ';
echo 'searchField.value+=", WA";';
echo '}';
echo '}';
echo '</script>';

(It's included in a Wordpress Plugin, hence the echo tags)and the form itself:
PHP Code:
echo '<form method="post" action="http://'.$current_site->domain . $current_site->path.'home/activity-search" onSubmit="javascript:checkState();return true;">';
echo '<label>Suburb:</label><input type="text" name="address" id="suburb-address" title="Enter Suburb & State" />';
echo '<select name="categories[]" >';
echo '<option value ="">All Activities</option>';
$categories_list = split('[
]', get_setting('categories', $db));
foreach ($categories_list AS $cat){
$cat = trim($cat);
echo '<option>'.$cat.'</option>';
} echo '</select>';
echo '<label>Country:</label>';
echo '<select name="country" id="country">';
echo'<option>au</option>';
echo '</select>';
echo '<label>Radius:</label>';
echo '<select name="radius" id="radius">';
echo'<option>15</option>';
echo '</select>';
echo '<input type="submit" name="submit" value="Search" class="btn" />';
echo '</form>';
I'm wondering whether the if statement is valid, but I'm not knowledgeable in Javascript, so I don't know where to begin.

View 3 Replies View Related

Get Last Entry Of An Array?

Feb 27, 2009

I have a value, j[i] , which Ineed to do the following with:1) split with / to make an array2) Return the last valueFor example:Continent/country/State/City..and it would return "City", and with:Continent/country/State..it would return "State"Can anyone point me in the right direction?In Perl, I would just do:

my @tmp = split ///, $val;
my $last_val = $tmp[$#tmp];

View 2 Replies View Related

Index Of An Array Entry

Mar 24, 2006

I'm refering to an entry in an array by it's string key, as in
foo["bar"]. Is there a way to get the numeric index of that array
without iterating through the entire array?

What I need to do is find the "next" or "previous" entry in the array,
but the keys are strings, instead of numerical indeces.

View 6 Replies View Related

Accessing An Array Entry's Item?

Oct 29, 2009

I created an array, whose entries looks like this:

[41, "The bird flew into it's cage"]
[33, "He drew fire from Joe"]
[33, "Roger asked her her name"]

[code]....

View 8 Replies View Related

Select A Random Entry From An Array?

Aug 30, 2010

So, I am attempting to select a random entry from an array, and then make it so that particular entry will not be selected again until every entry has been selected. Basically, I don't want to see any of the same entries, until all of the entries in the array have been selected.

So if this were my array....

keywords =
[
"ppc",
"games",

[Code]....

since meta was selected a second time before everything had been selected once.

I would like to see something more like

meta, advertise, gaming,ppc, welcome, home, games, advertise, ppc, since this did not select any entry multiple times before every entry had been randomly selected.( the second loop started at the second "advertise" in case you didn't catch the differences.

But as you can see from the code that I have posted above, I do not know how to do this. I have seen examples where the entries that were randomly selected, were actually deleted from the array entirely but this is not what I want to do. I just want every entry to be selected once, and then for the process to be restarted.

View 3 Replies View Related

Remove Entry From Array And Repost Form?

Mar 16, 2009

I am trying to accomplish a fairly basic task with javascript > my lack of Js knowledge has meant i have hit something of a roadblock.I need the a function to take an array from a form, remove the parsed variable from it and repost the form with the new array.This is what I have so far...

<script language="javascript">
function remove(SID) {
var speakers = document.form_name.elements["SID[]"];

[code]....

View 2 Replies View Related

Auto-suggest Array Search - From The Data Stored In Array

Nov 19, 2011

I want to have a simple code such that some data is stored in array. When we create a search box it has to give suggestions from the data stored in array.

View 4 Replies View Related

Form Entry To Time Part Of Database Date Entry?

Aug 1, 2005

I have a textbox on one of my forms that is used to accept a time from the
user. I need to write this value to a database to trigger an event later on.

What I'd like to know is...

Are there any functions in javascript that can convert different time
formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00,
etc. ???

Assuming that I get the input into a 24 hour format, how can I create a full
time/date variable with todays date and the users entered time?

Finally, if the entered time is earlier than the current time, how can I
create the above date/time combination using tomorrows date?

View 2 Replies View Related

How To Search An Array

Apr 23, 2011

I have the following array in a chatbot

Code:

Sites=new Array("alcatraz,California in the USA","eiffel tower,Paris in France","empire state building,New York in the USA");

This piece of code searches the first part of the array and triggers the second part as a response. That all works fine. However, could it be rewritten in a way to eliminate the bailout response of "I don't know." to where it just skips over it if no match is found.I have more If statements further down the script that I want to use instead of the one bailout response. If nothing matches I have one big catchall to respond back with at the very end.

Code:

if (input.search("where is")!= -1)
{document.result.result.value = "I don't know.";
for (i=0; i<Sites.length; i++) {

[code]....

View 2 Replies View Related

Banning Certain Words Being Inputted By The User?

Aug 5, 2009

Do you know a function for banning certain words being inputted by the user eg I want to stop a user uploading offensive words and code tags like <script>, <div> etc.. and messing with the site display

View 8 Replies View Related

Output Characters As They Are Inputted Into An Input Box?

Aug 26, 2009

How I can output the characters as they are inputted into an input box...

View 4 Replies View Related

Search And Replace Through Array?

Jun 29, 2009

i have a implementation where i need to perform a search and replace. i will try to explain to the best of my ability. i have a variable, var a = "THIS IS SOME SOME TEXT";

then i have another array variable, var b = new Array(); which contains elements in key=value format eg. SOME=NEWSOME so what i need to do is, i need to loop through this array and if SOME exists in var a, then i need to replace it with NEWSOME. so for each value before =, if it exists in var a replace it with whats after =. and replace only once, so if SOME exists multiple times just replace the first occurence.

so essentially my final string would be, THIS IS NEWSOME SOME TEXT.

View 1 Replies View Related

Search And Delete Value From An Array?

Aug 9, 2009

I have an javascript array and i want to search for an element inside the array and then delete that value from the array . How can i do that? I can use splice to remove an element based on index but how can i search and find the index?

I used array.indexOf('str') but it worked only on firefox but not IE..

View 3 Replies View Related

Search And Replace Through Array

Jun 29, 2009

i have a implementation where i need to perform a search and replace. i will try to explain to the best of my ability. i have a variable,

[Code]...

View 5 Replies View Related

JQuery :: Only Allow Characters And Numbers Inputted Into The Text Box?

Dec 30, 2010

I made a form with text inputs but notice you can use special symbols. I want to only allo charaters like letters and numbers that is it.Is there any jquery function that cna do such a thing... if not how do you implement something that will filter it.

View 3 Replies View Related

Possible To Search An Array Without Looping Through All The Elements?

Aug 24, 2006

Is it possible to search an array without looping through all the elements?

hoping for something like this;

myarray.exists("one")

which may return the element number or a true or false depending if the element being searched exists.

View 14 Replies View Related

Get The Index Of An Array From A Partial Search?

Apr 8, 2009

I have an array in which each element is a long string of various values separated by a particular character.I want to be able to search the array using the first value of each element to get the index.I cannot see how to do this so I have started to create a function for this.I want to take the original array, split out the value into another array and search the new array.I can then use the index returned to retrieve the full string from the original array.However I am having a problem when trying to set the new array and I do not know enough JS to understand what is going wrong.Here is the code:

Code:
<script type="text/javascript">
var test= new array();[code].......

I am getting the correct result in "title".I have tried setting "test[0]=title;" with an if on the first pass and then using ".push" but to no good effect.if there is a better way to achieve my objective or is this a reasonable solution

View 2 Replies View Related

Can I Use JS To Search Folder And Create Array From Files

Jan 9, 2007

I would like to put all my .jpg images in a folder into an array to be
viewed. can I use JS to do this automatically. Without having to type
by hand?

View 8 Replies View Related

Can I Randomly Search An Array In A .js File Not On My Page?

Jan 9, 2007

If I have a .js file filled with data like links. how do i access just
1 element [random] and bring it on my page

View 2 Replies View Related

Search In Array / String For Individual Characters

Nov 3, 2011

I'm writing a piece of JS code that returns a result of true if the pattern appears in string as a substring (case sensitive) but would like to extend its functionality to returns true if all the individual characters of pattern appear in string (regardless of order).

View 1 Replies View Related

Search In Array Or String For Individual Characters?

Nov 3, 2011

I'm writing a piece of JS code that returns a result of true if the pattern appears in string as a substring (case sensitive) but would like to extend its functionality to returns true if all the individual characters of pattern appear in string (regardless of order).

For example:This is what the program currently does:

match1("adipisci","pis") returns true

Whereas I would now like it to do this:

match1("adipisci","sciip") returns true
match2("adipisci","sciipx") returns false because x does not exist in variable
match3["adipisci","adipisci"] returns true in array 1 and 2 if "sciip" is searched
match4["adipisci","adipiscix"] returns false in array 1 and true in array 2 if "sciipx" is searched

I am having difficulty implementing this into my code... this is what I've done so far:

var pages=[
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Nulla imperdiet laoreet neque.",

[code]....

View 3 Replies View Related

Parallel Array Multiple Search - Mandatory And Optional

Sep 18, 2010

I have 4 arrays that all contain data linked by the index. I have 3 drop down boxes on a web page that give the user 3 ways to search for data. The top one is mandatory the other two are optional. I've managed to create the code to search using the mandatory box but cant figure out how to expand the search.

Here is the function that deals with the search data:
function findFlights(){
var yourAirline = readTheAirline();
var result = 'Here are your flights <BR>';
var choose = 'Choose your destination';

for (var index = 0; index < flightTimes.length; index++){
var flight = flightDestinations[index];
var airline = flightOperators[index];
if (yourDestination == flight){
var b = flightTimes[index];
var c = flightDestinations[index];
var d = flightOperators[index];
var e = flightFares[index];
var message = b + ' to ' + c + ' operated by ' + d + '. £' + e + '.';

result = result + message + '<BR>';
}if (yourDestination == choose){
result = 'Please choose a destination city from the destination menu and then click Find flights again.';
}}displayMessage(result);}

View 3 Replies View Related

Search And Pass An Array And String And Replace The Value In Return

Apr 1, 2010

trying to write a function where i can pass an array and string and replace the value in return. i.e

var inputStr = "010203040506070809111213141516171819";

i want to pass this value in function and replace each number (number ranges are 01-09 and 11-19 only) i.e if i pass 01 want to replace that with A,02 with B etc.. so problem is i would pass input string and pass back as string after replacing those values by running through the below function. wrote the following,cant seem to split my inputStr into 01 02 etc tried splice and split no luck :

[Code]....

View 2 Replies View Related

Unable To Execute Function Designed To Calculate The Average Of Numbers Inputted?

Oct 4, 2010

I've been messing with this code for about a couple of hours, and I did everything down to the wire..yet still I am unable to get it to work. When I input the numbers, and click off to the side nothing appears down at the final textarea of the form which is suppose to show the average.I've tried just about everything, sadly all I have to go by is other example codes, and the very intricate instructions which states I must pass the values to the calcAvg() to the second function of performCalc(), which I did, and then I assigned the var calcResult another value. From there I did the return..and after that I'm rather loss as to what to do next to get this code to work, any tips?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

[code]....

View 2 Replies View Related

If Else - When I Input An Invalid Or A Valid Entry, It Is Continuing To Ask Me To Input Again An Entry?

Jan 17, 2010

There is a missing part on my program, it is when you input less than or equal to 65 and greater than 100, a prompt will appear and say "Invalid Entry" and ask you to Input again an entry until you enter a valid entry. For example on Prelim Grade, I input 50, a prompt must appear to say "Invalid Entry" and ask me to input again another entry. Another is how will I terminate the program? When I input an invalid or a valid entry, it is continuing to ask me to input again an entry.Here is my code

Code:
<html>
<head>[code]......

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved