Log in

View Full Version : I need simple storage & retreval of Information



trazix
08-26-2007, 02:28 PM
I would like a script where i could easily store contact information (in an Array) on various business e.g.

Name, Address,Phone Number, Fax Number, E-mail Address & Website Address. Then in the web page when you click

on a link for Hotels then all the hotels will be displayed with their contact details or if you click on a

link for Restaraunt all the restaraunt contact details will display. I have searched all over the net for

this but i can't find a sample script that would do what i want. Is this possible to do with Javascript

because it's not going to be a large database and i dont want to get into Php or Mysql database that would

:eek: wreck my head:eek: .

I would be very greatful if someboby could write a simple or a complex script to get me started as i do not

know how to program in Javascript.


I think i have posted this in the wrong section it should be in the i need a script section. Very sorry but i am new

Many thanks... :confused:

thetestingsite
08-26-2007, 04:10 PM
Probably not the best way to accomplish it, but this is just something that I came up with off the top of my head. Simply edit the contacts.js file (where it says "CONFIG") to list your contacts. If you would like a demo of what it does, go to http://phphost.smackum.com/dd/test/test.html.

Hope this helps.

trazix
08-26-2007, 05:26 PM
You are a super fast Genius thetestingsite. Thank you very much


Is there a limit to the amount of information that can be stored in a .js file.

thetestingsite
08-26-2007, 05:30 PM
Other than the maximum size of your disk space (on your server), there is no limit. Keep in mind; though, the more you put in the js file the longer it will take to load the info. When I get the time, I will post the PHP/MySQL equivalent to this so that when you are ready to upgrade, it will be a simple transition.

Hope this helps.

trazix
09-02-2007, 02:18 PM
The script that you provided works perfectly however :eek: when you begin filling in the data fields it becomes very clutered and it can become hard to edit :confused: in future if you need to.

Would it be possible to store the data in a less cluttered way like this. :rolleyes:

Category[1] = "Hotels"
Title[1] = "Name of Hotel 1"
Address[1] = "Address"
Phone[1] = "1234567890"
Fax[1] = "0987654321"
Email[1] = "name@Domain.com"
Website[1] = "www.name.com"

Category[2] = "Hotels"
Title[2] = "Name of Hotel 2"
Address[2] = "Address"
Phone[2] = "1234567890"
Fax[2] = "0987654321"
Email[2] = "name@Domain.com"
Website[2] = "www.name.com"

Category[3] = "Hotels"
Title[3] = "Name of Hotel 3"
Address[3] = "Address"
Phone[3] = "1234567890"
Fax[3] = "0987654321"
Email[3] = "name@Domain.com"
Website[3] = "www.name.com"


Category[4] = "Restaraunts"
Title[4] = "Name of Restaraunt 1"
Address[4] = "Address"
Phone[4] = "1234567890"
Fax[4] = "0987654321"
Email[4] = "name@Domain.com"
Website[4] = "www.name.com"

Category[5] = "Restaraunts"
Title[5] = "Name of Restaraunt 2"
Address[5] = "Address"
Phone[5] = "1234567890"
Fax[5] = "0987654321"
Email[5] = "name@Domain.com"
Website[5] = "www.name.com"

Category[6] = "Restaraunts"
Title[6] = "Name of Restaraunt 3"
Address[6] = "Address"
Phone[6] = "1234567890"
Fax[6] = "0987654321"
Email[6] = "name@Domain.com"
Website[6] = "www.name.com"


Then when you click a link for hotels it displays only the hotel datails

Also i would like the output to be displayed in a table where i can style the various elements with css.


Would this be possible to do.

thetestingsite
09-02-2007, 03:19 PM
It would be, I would need to play around with it a little bit when I have the time, but it shouldn't be that hard. Also; as said before, you may want to use a database (MySQL/MS SQL) and server-side language (PHP/ASP) to store and retrieve this data. It would be easier to maintain and a lot less cluttered.

For more info on how to do this, check out http://www.php-mysql-tutorial.com/.

Hope this helps.

thetestingsite
09-02-2007, 07:32 PM
Ok; as promised, here is the modified version of contacts.js. I tested it and it works fine, but you can test it as well by going to the same link I posted in my second post.

Hope this helps.

trazix
09-05-2007, 07:49 PM
Thank you for the script. :) :) :) :)

boogyman
09-05-2007, 08:04 PM
It would be, I would need to play around with it a little bit when I have the time, but it shouldn't be that hard. Also; as said before, you may want to use a database (MySQL/MS SQL) and server-side language (PHP/ASP) to store and retrieve this data. It would be easier to maintain and a lot less cluttered.

For more info on how to do this, check out http://www.php-mysql-tutorial.com/.

Hope this helps.


using a database also secures the integrity of the data better, since anyone can see the javascript file.

thetestingsite
09-05-2007, 08:14 PM
Indeed; however, in this case I don't think that is an issue mostly due to the fact that the information in the javascript file is being displayed on the webpage anyway for anyone to see. This is a good point; though, just in case this project gets larger and you have more valuable info that needs to be stored.

trazix
09-09-2007, 07:03 PM
If i want to expand the database with new catagory's (for example if i want to add shops , cafe, bars etc)what would i need to do to the script at the end of the array.

thetestingsite
09-09-2007, 08:24 PM
Would this be like the resturants and hotels arrays? If so, then simply copy those arrays and change the name of the array to whatever category you want. Then in the display function, add this before the last "else" statement.



elseif (which == 'NEW ARRAY NAME HERE') {
//copy out the other else if statements in this
}


Hope this helps.

trazix
09-16-2007, 07:06 PM
Thanks once again for your help.

I did try this but i am getting errors in the browser ( ie7 ), I have tracked them down to these lines

<a href="#" onclick="displayContacts('resturants'); return false;">Resturants</a> |
<a href="#" onclick="displayContacts('hotels'); return false;">Hotels</a> |

Depending on which link you click on you get the error on that line,
the error says

line: 111
char: 1
Error: object expected
code: 0


I cant see anything wrong with it as they worked before i expanded the database.

I checked the .js file for missing characters like ' & ; and all seems ok i just cut & paste everything so there should be no mistakes there.

Any ideas what is wrong

thetestingsite
09-16-2007, 07:17 PM
Can you post what you have editted, just to make sure that it is not a simple syntax error that you (as many others) can simply overlook.

trazix
09-16-2007, 07:39 PM
The .js directory file is attached to this post

thetestingsite
09-16-2007, 07:46 PM
Ok, try the file I have attached. What I found was wrong was on some of the entries you posted. You must remember to escape all single quotes ( ' ) in the strings with a backslash ( \' ) so it doesn't error out. Other than that, the rest of the file should be fine.

Hope this helps.

trazix
09-16-2007, 07:59 PM
Once again thank you

I have sceen the 'Syntax' Error of my way \'s

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have another post at

http://www.dynamicdrive.com/forums/showthread.php?p=108684#post108684

which has had no reply's

Could you take a look you might be able to do something.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~