Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:17:46+00:00 2026-06-05T17:17:46+00:00

I am building an array in javascript, using JSON.stringify() on it, and then setting

  • 0

I am building an array in javascript, using JSON.stringify() on it, and then setting a hidden input field’s value attribute to the resulting string.

function setSelectedArray(){

        var ticketInfo = new Array();   //creates new array for later
        var num=0;                      //num accumulates the number of the next row
        for(var i=0;i<hlRows.length;i++){
            if(hlRows[i]){  //hlRows is an array with boolean values telling me
                            //which dataArray values to set ticketInfo to
                ticketInfo[num] = dataArray[i];
                //dataArray is a pre-defined array and contains a large amount of data
                //ticketInfo is a smaller array that is gathering all data specified from hlRows
                num++;
            }
        }
        //line below sets 'tix'(hidden input field).value to the JSON version of ticketInfo
        document.getElementsByName('tix').value = (JSON.stringify(ticketInfo));

        //At this point, my alert below displays everything I want to see.
        //It looks like correct JSON to me
        alert("The VALUE of 'tix' is: "+document.getElementsByName('tix').value);

        //this submits the form that the hidden field is inside of.
        //it wouldn't go to the next page(which it does) without
        //this calling the form's action attribute correctly (i think..)
        document.forms["hiddenForm"].submit();
    }

You can read my comments if you need more description. Here is the HTML part of the process:

<!-- This button, when clicked, calls the setSelectedArray() function -->
<input class="button" type="button" id="btnContact" value="Select Tickets" onclick="setSelectedArray()" style="width:20em;float:right;"/>

<form id="hiddenForm" action="email.php" method="post">
    <input type="hidden" name="tix" value=""/> <!-- I tried this with no value specified too -->
</form>

I don’t know how many different things I tried in email.php to just get any sort of output.
I tried echos and print and print_r and print from loops and printing values inside the “array”, but nothing seemed to work. Here is where email.php is at right now:

<?php
    $jsArray = json_decode($_POST['tix']);
    var_dump($jsArray);
?>

The only output I get from email.php is “NULL”(which it wasn’t 2 seconds earlier in the alert) or “Array”. Otherwise, it says nothing and I just get an empty screen. What am I doing wrong here? Do I need to use AJAX to post the data? I feel like that isn’t right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:17:48+00:00Added an answer on June 5, 2026 at 5:17 pm

    You problem is that getElementsByName returns an array of elements.

    document.getElementsByName('tix')[0].value = (JSON.stringify(ticketInfo));
    
    alert("The VALUE of 'tix' is: "+document.getElementsByName('tix')[0].value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a guestlist app for my company using PHP, Javascript/jQuery/Ajax, JSON and localstorage.
I am building a JavaScript array depending on the input of the user. The
I'm building a game in Javascript using canvas which requires collision detection, in this
I'm building a simple puzzle app for and iPad using a JavaScript library for
I'm building a simple Javascript jukebox using the latest SoundManager2 for audio playback, with
I'm having a problem handling JSON data within JavaScript, specifically in regards to using
I'm building a webapp using php, ajax, javascript, mysql. I've been worring about something
I am building a request in Flash that contains a JSON encoded Array of
i'm building an MVC3 site and using Knockout / JSON for the first time,
I am building a prototype for a website and I am using a JavaScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.