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 6322035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:24+00:00 2026-05-24T16:15:24+00:00

I have an html like below HTML: <INPUT TYPE=CHECKBOX NAME=clcik onClick=add(‘1234′,’blah’) /> <input type=hidden

  • 0

I have an html like below

HTML:

 <INPUT TYPE=CHECKBOX NAME="clcik" onClick="add('1234','blah')" />
 <input type="hidden" id="project" value="" />

JS:

    function add(obj1 , obj2){
    var jsonArray = [];
    var jsonObj = { product_id : obj1 , name : obj2 };
    jsonArray.push(jsonObj);
    var field = document.getElementById('project');
    field.setAttribute('value', JSON.stringify(jsonArray));
    alert(field.getAttribute('value'));
    }

I am trying to set first and retrieve again to check but nothing is happening..I can’t understand where I am wrong…?

  • 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-05-24T16:15:25+00:00Added an answer on May 24, 2026 at 4:15 pm

    I guess you missed to get the stringify result into stringData variable because of which you are getting a js error before it reaches the line where you are trying to alert the value.

    JSON or JSON.stringify is not provided by jQuery you have to include json2 library on the page if the browser natively do not support it.

    Try this

    function add(obj1 , obj2){
        var jsonArray = [];
        var jsonObj = { product_id : obj1 , name : obj2 };
    
        jsonArray.push(jsonObj);
        var stringData = JSON.stringify(jsonArray);
    
        var field = document.getElementById('project');
    
        field.setAttribute('value', stringData);
        alert(field.getAttribute('value'));
    }
    

    Code to remove element from array based on your request in the comment.

    var newArray = [], productIdToRemove = "1234";
    $.each(jsonArray, function(){
       if(this.product_id != productIdToRemove){
          newArray.push(this);
       }
    });
    
    //Now newArray will not have '1234'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got below ASP html <div id=divCheckAll> <div class=selectall> <input type=checkbox id=chkOperationalUpdate name=chkOperationalUpdate
I have HTML code like below <input type = textarea id=sentence1> Here is my
I have the below code in my .aspx page. <input type=hidden id=fbinfo name=fbinfo value=
I have the following HTML <form id=create_form name=create_form action= method=post> <input name=type id=type value=individuel
I have a HTML input box in my ASPX page like below <input id=txtID
I have a simple form with some plain html input like bellow using ASP.NET
I have a html like this: <html> <head> <link rel=stylesheet type=text/css media=all href=style.css> </head>
I have created a simple layout with Html and CSS which is like below
I have a simple html form like this <table> <tr><td >Topic: </td> <td> <input
I have a table setup like below: <table> <tr> <td class=url> <a href=http://www.domainname.com/page1.html />

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.