{"id":119,"date":"2022-10-04T12:55:39","date_gmt":"2022-10-04T12:55:39","guid":{"rendered":"https:\/\/jassweb.com\/new22\/solved-get-value-in-javascript-closed\/"},"modified":"2022-10-04T12:55:39","modified_gmt":"2022-10-04T12:55:39","slug":"solved-get-value-in-javascript-closed-2","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/","title":{"rendered":"[Solved] Get Value in JavaScript [closed]"},"content":{"rendered":"<h2> Introduction <\/h2>\n<p>[ad_1]<\/p>\n<p>JavaScript is a powerful scripting language that can be used to create dynamic webpages and applications. It is often used to manipulate data and create interactive elements on a webpage. One of the most common tasks in JavaScript is to get the value of a variable or object. This can be done using the built-in functions provided by JavaScript. In this article, we will discuss how to get the value of a variable or object in JavaScript. We will also discuss some of the best practices for getting values in JavaScript.<\/p>\n<h2> Solution<\/h2>\n<p><\/p>\n<p>You can use the dot notation or bracket notation to get the value of a property in JavaScript.<\/p>\n<p>For example, if you have an object called &#8220;person&#8221; with a property called &#8220;name&#8221;, you can get the value of the &#8220;name&#8221; property using either of the following:<\/p>\n<p>\/\/ Dot notation<br \/>\nlet name = person.name;<\/p>\n<p>\/\/ Bracket notation<br \/>\nlet name = person[&#8216;name&#8217;]; <\/p>\n<p><\/p>\n<div itemprop=\"text\">\n<p>To fix your code:<\/p>\n<ol>\n<li>\n<p>Add the <code>event<\/code><\/p>\n<pre><code>function doit_onkeypress(a, event) {\n<\/code><\/pre>\n<p>\u2026<\/p>\n<pre><code>&lt;p id=\"para\" tabindex=\"0\" onkeypress=\"javascript:  doit_onkeypress(this.id, event);\"&gt;\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Add the id into the jQuery selector<\/p>\n<pre><code>$(\"#\" + a + \".token\").each(function () {\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Add a tabindex to paragraph, so that it can be focused.<\/p>\n<\/li>\n<\/ol>\n<p>This is how it works for me:<\/p>\n<pre><code>&lt;html&gt;\n&lt;head&gt;\n\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;p id=\"para\" tabindex=\"0\" onkeypress=\"doit_onkeypress(this.id, event);\"&gt;\n    &lt;span class=\"token\"&gt;test1&lt;\/span&gt;\n    &lt;span class=\"token\"&gt;test2&lt;\/span&gt;\n    &lt;span class=\"token\"&gt;test3&lt;\/span&gt;\n&lt;\/p&gt;\n\n&lt;p id=\"para2\" tabindex=\"1\" onkeypress=\"doit_onkeypress(this.id, event);\"&gt;\n    &lt;span class=\"token\"&gt;test4&lt;\/span&gt;\n    &lt;span class=\"token\"&gt;test5&lt;\/span&gt;\n    &lt;span class=\"token\"&gt;test6&lt;\/span&gt;\n&lt;\/p&gt;\n&lt;script&gt;\nfunction doit_onkeypress(a, event) {\n    debugger;\n    if (event.keyCode == 13 || event.which == 13) {\n        alert(a);\n        var splitdata;\n        span_array = [];\/\/define array\n\n        $(\".token\").each(function () {\/\/ iterate over same class spans\n            console.log($(this).text()); \/\/ print the text of each span\n            span_array.push($(this).text());\/\/ push span text to array\n        });\n        console.log(span_array); \/\/ you can save data an array for further use\n        var final_string = span_array.join(); \/\/join array value as string\n        console.log(final_string); \/\/ check string \n        splitdata = final_string\n        document.getElementById(\"hdnvaluearray\").value = final_string;\n        document.getElementById(\"hdnvaluearray\").value = a;\n    }\n}\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<\/div>\n<p>[ad_2]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction [ad_1] JavaScript is a powerful scripting language that can be used to create dynamic webpages and applications. It is often used to manipulate data and create interactive elements on a webpage. One of the most common tasks in JavaScript is to get the value of a variable or object. This can be done using &#8230; <a title=\"[Solved] Get Value in JavaScript [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\" aria-label=\"More on [Solved] Get Value in JavaScript [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[346,333,388],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-solved","tag-html","tag-javascript","tag-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Get Value in JavaScript [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Get Value in JavaScript [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"Introduction [ad_1] JavaScript is a powerful scripting language that can be used to create dynamic webpages and applications. It is often used to manipulate data and create interactive elements on a webpage. One of the most common tasks in JavaScript is to get the value of a variable or object. This can be done using ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-04T12:55:39+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Get Value in JavaScript [closed]\",\"datePublished\":\"2022-10-04T12:55:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\"},\"wordCount\":190,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"html\",\"javascript\",\"jquery\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\",\"name\":\"[Solved] Get Value in JavaScript [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-04T12:55:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Get Value in JavaScript [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Get Value in JavaScript [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Get Value in JavaScript [closed] - JassWeb","og_description":"Introduction [ad_1] JavaScript is a powerful scripting language that can be used to create dynamic webpages and applications. It is often used to manipulate data and create interactive elements on a webpage. One of the most common tasks in JavaScript is to get the value of a variable or object. This can be done using ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/","og_site_name":"JassWeb","article_published_time":"2022-10-04T12:55:39+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Get Value in JavaScript [closed]","datePublished":"2022-10-04T12:55:39+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/"},"wordCount":190,"commentCount":0,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["html","javascript","jquery"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/","url":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/","name":"[Solved] Get Value in JavaScript [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-04T12:55:39+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-get-value-in-javascript-closed-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Get Value in JavaScript [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}