views:

35

answers:

1

I have x = 65; in a javascript page /var/html/pag1.js and I want to pass x to a different page: /var/html/user1/pageUser.js

What's the easiest way to send a value like that?

Thanks.

+2  A: 

Your question is a little unclear. In an attempt to decipher and give a good answer, I'll restate your question. I believe you are trying to 'post' a field called 'x' with value of '65' to another page. You say you have a 'page' with name 'page1.js', but that is a script and not a page. You might have a 'page1.html' that references 'page1.js' (same for page2). I'll proceed on the assumption you have 2 files:

  1. page1.html
  2. page1.js
  3. page2.html
  4. page2.js

Normally, data is passed between pages using form actions like this...

Page1.html:

<body>
    <form action='page2.html' method='post'>
        <input type='text' name='x' value='65' />
        <input type='submit' />
    </form>
</body>

If you want to do this using javascript, you can should look into jquery and it's post() method. Here's an example in context...

Page1.html:

<body>
    <script type='text/javascript'>
        $.ajax({
            type: 'POST',
            url: 'page2.html',
            data: { x : 65 },
        });
    </script>
</body>
Byron Sommardahl
As best as I can figure out his question, your second example is a good solution to what he's asking...
Josh