Online Demo : http://jsfiddle.net/thefourtheye/jRym8/

<html lang = "en">
    <head>
        <title> Document </title>
        <script>
            function filterFilms(selectBox) {
                var displayArea = document.getElementById("displayArea");
                displayArea.innerHTML = selectBox.id + "," + selectBox.value + "," + selectBox.selectedIndex + "," +
                    selectBox.options[selectBox.selectedIndex].text;
            }
        </script>
    </head>
    <body>
        <select onchange="filterFilms(this);" id="films">
            <option value="film1">Film Text 1</option>
            <option value="film2">Film Text 2</option>
            <option value="film3">Film Text 3</option>
        </select>

        <select onchange="filterFilms(this);" id="colors">
            <option value="color1">Color 1</option>
            <option value="color2">Color 2</option>
            <option value="color3">Color 3</option>
        </select>

        <div id="displayArea"/>
    </body>
</html>

You can use the same function to do this. Pass the current element as the parameter. And

  1. You can get the id of the select box clicked with selectBox.id
  2. You can get the selected option's value with selectBox.value
  3. You can get the selected option's index with selectBox.selectedIndex
  4. You can get the selected option's text with selectBox.options[selectBox.selectedIndex].text
Answer from thefourtheye on Stack Overflow
🌐
Bytes
bytes.com › home › forum › topic › javascript
Pass an html array to javascript - Post.Byes
July 13, 2008 - <script language="JavaScript"> function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } function handle_button(field) { for(i = 0;i < field.length; i++) if(field[i].checked == false) { checkAll(field); return; } uncheckAll(field); } </script> Then in the HTML
🌐
YouTube
youtube.com › the amazing codeverse
Send an Entire Array from one Page to Another Page using JavaScript - YouTube
send array from one page to another JSpass information from one html page to anothersend json array from one page to other Javascriptget and set data with se...
Published   October 22, 2020
Views   7K
Top answer
1 of 2
4

Pass data using Session Storage or Local Storage: (basic example)

You can pass data from one page to the next using sessions storage. Alternatively you can also use local storage which behaves in similar fashion. Except local storage will not be cleared when the session is closed.

For local storage just replace sessionStorage with localStorage.

Array to store:

var testArray = ['test'];

Storing the Array:

$('#store').on('click', function(){
    sessionStorage.setItem('myArray', testArray);
});

Getting the Array:

$('#get').on('click', function(){
    var myArray = sessionStorage.getItem('myArray');
    alert(myArray);
});

Clearing the Session Storage:

$('#clear').on('click', function(){
    sessionStorage.clear();
});

HTML:

<a href="javascript:void(0);" id="store">Store Array</a>
<a href="javascript:void(0);" id="get">Get Array</a>
<a href="javascript:void(0);" id="clear">Clear</a>

Checking to see stored session in chrome:

If storing stringified data, make sure to convert back to JSON:

var mydata = localStorage.getItem("GoogleLatLng");
var myObject = JSON.parse(mydata);

DEMO:

http://jsfiddle.net/mdktpmw2/

Supporting older versions of Internet Explorer:

  • http://modernizr.com/docs/
  • https://github.com/pamelafox/lscache
  • http://amplifyjs.com/

Some Resources:

  • http://caniuse.com/#feat=namevalue-storage
  • http://davidwalsh.name/html5-storage
2 of 2
0

You'll want to post the data to another page. There are a ton of tutorials that can walk you through it, including some Stack answers that have already been answered:

how can i send the data to another page without appending it in url?

passing form data to another HTML page

You'll probably want to grab the data in your onLoad of the next page.

🌐
Code Boxx
code-boxx.com › home › 5 ways to pass php variables & arrays to javascript
5 Ways To Pass PHP Variables & Arrays To Javascript
October 19, 2023 - ... <?php // (A) PHP CONVERT ARRAY ... = JSON.parse('<?=$phpvar?>'); console.log(jsvar); </script> Sadly, we cannot pass an array (or object) as it is....
🌐
Stack Overflow
stackoverflow.com › questions › 35192649 › passing-a-javascript-array-through-html-form-to-another-js-file
Passing a javascript array through HTML form to another js file - Stack Overflow
May 23, 2017 - You can submit to the server JS arrays and objects by AJAX (XmlHttpRequest). There are many handy wrappers for it e.g. in jQuery. ... Edited my post with more details. Added the questions.json, formatted html
Find elsewhere
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 448871 › passing-an-string-array-to-javascript-function
java-jsp - passing an String array to javascript function | DaniWeb
Java is NOT javascript. They are 2 completely different things, not related in any way whatsoever (except the name) ... input fields,divs,spans,and so on (based on our requiement we can hide these html elements also for not showing anything to user) you can access your values diffinately from your java script. ... <% String my_str_values = "value1,value2,value3" // instead of string array you better to take string of values seperated by commas %>
🌐
Quora
quora.com › How-can-I-pass-a-PHP-array-to-JavaScript
How to pass a PHP array to JavaScript - Quora
Answer (1 of 5): You can pass PHP array by converting it in JSON and printing it inside a script tag with the scope you prefer OR if you want your PHP array to be an JavaScript array, so there is also a way to do that as well. Here is an example [code]
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-pass-a-php-array-to-a-javascript-function
How to pass a PHP array to a JavaScript function? - GeeksforGeeks
July 11, 2025 - '"]' ?>; // Printing the passed array elements document.write(passedArray); </script> ... You can embed the PHP array directly into the HTML and access it from JavaScript by reading the value of a hidden input element.
Top answer
1 of 1
10

First of all, I'd make sure that supporting IE7 is actually required. It's a really old browser by now, and there are a lot of things that are much more difficult to do.

Anyway, as for sending multiple form values, there's a common - but informal - way of doing that without JSON. It's supported by some server-side languages/frameworks (notably PHP, where I think it started), so it might work for you.

It's all about naming your inputs using square brackets to namespace them.

Typically - again, this isn't a true standard, just an informal one - you would use a name like foo[bar] to specify that bar is a named sub-property of foo. Or you'd use the name foo[] multiple times to indicate that foo is an array (but this only works for plain value arrays).

Here, you need a little of both, something like this (I've skipped a lot of HTML just to make it clearer):

<form id="form">
    <input type="text" name="group_name">

    <div id="dynamic_form">
        <input type="text" name="members[0][name]">
        <input type="text" name="members[0][date]">

        <input type="text" name="members[1][name]">
        <input type="text" name="members[1][date]">

        <input type="text" name="members[2][name]">
        <input type="text" name="members[2][date]">
    </div>
</form>

E.g. what gets sent to the server would be something like:

group_name=SomeGroup
members[0][name]=Alice
members[0][date]=01/01/2015
members[1][name]=Bob
members[1][date]=02/01/2015
members[2][name]=Carol
members[2][date]=03/01/2015

This is roughly equivalent to a JSON structure like:

{
  "group_name": "SomeGroup",
  "members": [
    {
      "name": "Alice",
      "date": "01/01/2015"
    },
    {
      "name": "Bob",
      "date": "02/01/2015"
    },
    {
      "name": "Carol",
      "date": "03/01/2015"
    },
  ]
}

Again, I can't guarantee that how your server will understand it, but it's a common way to do things.

Even if your server-side code doesn't understand it automagically, it's still parseable; you just have to write a bit more code yourself.

The trick is of course to increment the number, when you add new fields. That can be done in many ways, though.

Alternatively, you simply name all your fields the same:

<input type="text" name="name">
<input type="text" name="date">
<input type="text" name="name">
<input type="text" name="date">
<input type="text" name="name">
<input type="text" name="date">

The browser will send all the values, but usually the server-side software has a rule for how to handle duplicate names, and keeps only the first or last one it sees. But again, you can access the raw request data, and parse it yourself, if you want. But there's a lot of work in doing that.

On a side-note: I'd avoid having duplication between the javascript and the HTML (right now, the page starts out with 1 set of member inputs in the HTML, and the rest get added using a string in the JavaScript. That means you have to keep both of them identical in order for things to work - not great.

🌐
Lage
lage.us › Javascript-Pass-Variables-to-Another-Page.html
Pass Javascript Variables to Another Page - Lage.us
Then get the values out of the array and put them into variables: var value1 = a[0]; var value2 = a[1]; var value3 = a[2]; Now: value1 == "data1", value2 == "data2", value3 == "data3" Copyright © Lage.us Website Development | Disclaimer | Privacy Policy | Terms of Use · PHP Snippets HTML Snippets Javascript Snippets CSS Snippets
🌐
Stack Overflow
stackoverflow.com › questions › 21305423 › how-to-pass-an-array-to-display-it-in-an-html-file-node-js
javascript - How to pass an array to display it in an html file? - Node.js - Stack Overflow
July 12, 2016 - You have to install express via node npm install express and go from there. ... var express = require('express'); var app = express(); app.use(express.bodyParser()); app.set('view engine', 'ejs'); app.register('.html', require('ejs')); app.get('/', ...
Top answer
1 of 2
1

Try this:

App.js

var earn = [100, 200];

var textfield1 = Ti.UI.createTextField({
    value: earn[0],
    keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
});
win.add(textfield1);

var textfield2 = Ti.UI.createTextField({
    value: earn[1],
    keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD,
});
win.add(textfield2);

var webview = Titanium.UI.createWebView({
    url: 'chart.htm'
});
win.add(webview);

webView.addEventListener('load', function (e) {
    webview.evalJS('createPie(earn);');
});

Chart.htm

<script type="text/javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" src="pie.js"></script>

<div id="pieCanvas" style="overflow: auto; position:relative;height:350px;width:380px;"></div>

<script type="text/javascript">
function createPie(arr) {
    var p = new pie();
    p.add("Jan", arr[0]);
    p.add("Feb", arr[1]);
    p.render("pieCanvas", "Pie Graph");
}
</script>

Checkout this link for more help : http://developer.appcelerator.com/question/73121/passing-variable-from-titanium-js-class-to-html-script-

2 of 2
0

Your earn array will not dynamically update when you change the textfields, if that is what you are asking. You have to listen for when the texfields fire change events, capture that event, and get the new values, now you can update the pie chart.

To make it so that up update the graph whenever someone changes the value in the texfields you need to do this:

/* app.js */
var textfield1 = Ti.UI.createTextField({
    value:' ',
    keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD, 
});
/* This is the important part */
textfield1.addEventListener('change', function(e) {
    var earn = [textfield1.value, textfield2.value];
    webview.evalJS('createPie(' + JSON.stringify(earn) +');');
});

var textfield2 = Ti.UI.createTextField({
    value:' ',
    keyboardType: Titanium.UI.KEYBOARD_NUMBER_PAD, 
});
/* This is the important part */
textfield2.addEventListener('change', function(e) {
    var earn = [textfield1.value, textfield2.value];
    // DO this
    webview.evalJS('createPie(' + JSON.stringify(earn) +');');
});

var webview = Titanium.UI.createWebView({
 url: 'chart.htm'
});

// Add views
win.add(textfield1);
win.add(textfield2);
win.add(webview);

And in your HTML (I've taken from Mohit's well crafted HTML):

<script type="text/javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" src="pie.js"></script>

<div id="pieCanvas" style="overflow: auto; position:relative;height:350px;width:380px;"></div>

<script type="text/javascript">
function createPie(arr) {
    var earn = eval(arr); // convert from JSON string to JS, alternatively use JSON.parse
    var p = new pie();
    p.add("Jan", earn[0]);
    p.add("Feb", earn[1]);
    p.render("pieCanvas", "Pie Graph");
}
</script>

Now you have the bones, you may have to mess with the createPie() function, check out the link Mohit sent, this is written out in detail there.