Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling array using Onclick in text box field

Status
Not open for further replies.

JavascriptQ

Programmer
Dec 20, 2010
1
US
<html>
<head>
<title>using text input to pull up array</title>
<head>
<body>
<!-- If anyone can use simplified java script to help me on this it would be appreciated. I want to have a search box and when the user types in a product such as "watch" or "camera" then the products and product_cost array that corresponds to it will display the product and cost. This search form will be on all of my pages -->

<script language="javascript" type="text/javascript">
var = product ();

product[0] = "watch";
product[1] = "camera";

var = product_cost ();
products [0] = "49.99";
products [1] = "399.99";


</script>

<form method="post" action="mailto:info@mysite.com">
Search for product: <input type="text" name="product" size="40" maxlength="40" value="&nbsp;type in the name of the product here" /><br />
</form>
</body>
</html>
 
I seriously think you need to take a step back and re-plan your website strategy.

If you are honestly going to deliver a client-side array of all of your products to every page, all of the time, it will be a massive amount of unnecessary data every user will be downloading every time.

Why not submit the form to a server-side process which does this lookup for you? That's how most search routines work, and so as an established coding pattern, you should have no problem finding examples of how to do this in whatever server-side language your web host supports.

If your web host doesn't support any server-side languages, I would:

a) Change hosts, and
b) Give up any idea of running any sort of ecommerce site using purely client-side code.

Hope this helps,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
I would strongly agree with Dan. However, If you really really really must do this client-side and I don't condone it at all, I would probably re-structure my arrays to have only one array instead of several where each key is the name of the product such that searching for a product automatically returns its price and any other info you ay want to have.

Code:
var myproducts=new Array();
var myproducts['camera']=new Array();
var myproducts['camera']['cost']='49.99';
var myproducts['camera']['description']="This is a camera";

var myproducts['watch']=new Array();
var myproducts['watch']['cost']='29.99';
var myproducts['watch']['description']='A cool watch';

...

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top