<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bilal Ahmed</title>
    <description>The latest articles on DEV Community by Bilal Ahmed (@bilalahmedts).</description>
    <link>https://dev.to/bilalahmedts</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F916048%2F1532aff0-72e8-429d-ab46-6d9413e22632.png</url>
      <title>DEV Community: Bilal Ahmed</title>
      <link>https://dev.to/bilalahmedts</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bilalahmedts"/>
    <language>en</language>
    <item>
      <title>How to show the retrieved values from local storage in javascript when the browser window of the form is duplicated?</title>
      <dc:creator>Bilal Ahmed</dc:creator>
      <pubDate>Fri, 26 Aug 2022 17:55:21 +0000</pubDate>
      <link>https://dev.to/bilalahmedts/how-to-show-the-retrieved-values-from-local-storage-in-javascript-when-the-browser-window-of-the-form-is-duplicated-p6m</link>
      <guid>https://dev.to/bilalahmedts/how-to-show-the-retrieved-values-from-local-storage-in-javascript-when-the-browser-window-of-the-form-is-duplicated-p6m</guid>
      <description>&lt;p&gt;I want to get the data in form fields when the browser window is duplicated. I am storing the data in local storage for the below form:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`&amp;lt;div class="col-sm-6"&amp;gt;
                    &amp;lt;div class="form-group"&amp;gt;
                        &amp;lt;label&amp;gt;CRU ID&amp;lt;/label&amp;gt;
                        &amp;lt;select name="cru_agent_detail_id" class="form-control select2" id="user_list"&amp;gt;
                            &amp;lt;option value=""&amp;gt;Select CRU ID&amp;lt;/option&amp;gt;
                            @foreach ($users as $user)
                                &amp;lt;option value="{{ $user-&amp;gt;id }}"&amp;gt;{{ $user-&amp;gt;cru_id }}&amp;lt;/option&amp;gt;
                            @endforeach
                        &amp;lt;/select&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;

                &amp;lt;div class="col-sm-6"&amp;gt;
                    &amp;lt;label for="exampleInputEmail1"&amp;gt;Agent Name&amp;lt;/label&amp;gt;
                    &amp;lt;input type="text" class="form-control" name="name" id="agent_name" placeholder="Agent Name"
                        readonly&amp;gt;
                &amp;lt;/div&amp;gt;`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The form's CRU ID field is a select box which is populated from database and upon the selection of the menu the name of agent is shown in agent name field. I am storing the values of the above fields in local storage but cannot fetch them in the input fields when the browser window is duplicated. The code I did for it is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`$(document).ready(function() {
        /* let id;
        id = localStorage.getItem('cru_id');
        console.log(id) */

        $('#user_list').change(function() {
            cru_id = $('#user_list').find(":selected").text();
            localStorage.setItem('cru_id', cru_id);
            get_cru_id = JSON.stringify(localStorage.getItem('cru_id'));
            console.log(get_cru_id);
            id = $(this).val();
            $.ajax({
                url: 'get-user-detail/' + id,
                type: 'get',
                dataType: 'json',
                success: function(response) {
                    let user = response.data
                    $("#agent_name").val(user.name);
                    agent_name = $("#agent_name").val();
                    localStorage.setItem('agent_name', $("#agent_name").val());
                    get_agent_name = JSON.stringify(localStorage.getItem('agent_name'));
                    console.log(get_agent_name);
                }
            })
        });
    });`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The values are stored in local storage but are not retrieve when the browser window is duplicated.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>html</category>
      <category>laravel</category>
    </item>
  </channel>
</rss>
