Is there a way to make a script that edits something on a different page.

ironboy

10-08-2011, 06:08 PM

The question is a bit unclear but

Yes, if you've opened that page in a window using javascript - then the script on the page in the opener window can do so (and vice versa).

You can also use bookmarklets to apply javascript to any page...

blaze4218

10-08-2011, 08:27 PM

Does your scenario involve
- one user looking at two pages simultaneously,
- or do you want a change made on one page to overwrite the values on another page that everyone will view (i.e. a page dynamically generated from database values),
- or do you want the next page that the user visits on your site to depend on something they did on the first page?

sherlockturtle

10-08-2011, 08:47 PM

I would wont if you bought an item then open a other page it would edit what you have.

blaze4218

10-08-2011, 08:53 PM

do you have a particular scenario in mind? I would like to recommend the third option to you for most cases, but if your scenario is different than my assumptions, then perhaps the second would be best.

blaze4218

10-08-2011, 09:02 PM

like a shopping cart, yeah, the third is what you need, but you might still need database access.

blaze4218

10-08-2011, 09:21 PM

You should really follow the forums guidelines about editing your previous posts.

Because of your edit in which you changed your requirements to a scenario:

1) I almost didn't read your comment giving a scenario because I thought I already read that post
2) Someone might try to keep going with ironboys train of thought and give you more examples on my first suggestion even though you have already ruled that out because your post no longer shows that you've ruled it out
3) The posts themselves make a little less sense with me asking you for a scenario after you have seemingly already provided one...

PS If you absolutely must make a change that completley alters the original post you should document it somehow, and add to it, not rewrite it.

Edit: I added the p.s.

blaze4218

10-08-2011, 09:41 PM

I can see that you have already researched cookies in another thread. So I would like to assume that you are not trying to alter the js on your new page, but rather modify it based on the cookies from the last page:

<div id="cart"></div>
<script>
myShoppingCart = GetMyCookies('shoppingcart') // This assumes you have already built a cookie function and just need to extract the shopping cart variable

myShoppingCart = myShoppingCart.split(',') // if you didn't already store the values in JSON format you could just split them by a delimeter

Now of course I make a lot of assumptions in this example, but I don't know what you already have, so this is more a proof of concept to help you see how to do the following:

1) Convert the values that you stored in your cookie (in what I assume to be a basic format with each item separated by a comma) into a useful array
2) Build html code by looping through an array object (this can be used no matter how you configured your cookies as long as they are in an ordered array before you invoke this)
3) Insert the pre-built html code into an already existing DIV element

sherlockturtle

10-08-2011, 10:59 PM

For the cookie i have been researching them but could you maby make a basic one to go with your example blaze?

blaze4218

10-09-2011, 01:09 PM

Of course. But I don't have a cut and paste cookie function, so I'll just use the one recommended by jassi.singh in your cookie thread. Also, in a shopping cart you would typically use a form, and forms don't require cookies because you can actually just submit the form data directly to the server...

Again, I kept this very simple, and didn't use any techniques that would keep the code clean because it might make it difficult to understand the flow of logic if there were loops and such. So you will want to optimize it a little(ok, a lot!)...
Now I want to stress that using cookies to make a shopping cart seems like a really bad idea to me. If you really want to make one but don't have the know how to use a serverside scripting language you should just look for a prebuilt free shopping cart with paypal already integrated...
So there it is. I think I got everything, but to be honest, I'm a little drunk, and it's 4 in the morining, so I'm not going to test it (or even proof read it). I think I'm just gonna go sleep for like 16 hours. good luck

Edit
I forgot to test the cookie value before writing to the document- see blue changes

sherlockturtle

10-09-2011, 02:31 PM

thanks blaze. If you used submit how would you make the submit function flow data to the data base?

blaze4218

10-09-2011, 07:54 PM

That's an excellent question. You are going to need a server-side scripting language to write to the database. In order for anyone to help you on that, your going to need to first choose a server-side language. And questions regarding server-side scripting should go in the server side development forums in the appropriate language category. You could post them here, but you'll get better responses and feedback there.