Jump to content

Javascript into QR Generator


Recommended Posts

Hi there,

Previously @TellMeWhy helped to display values in a span tag which worked great:

<div class="col mr-2">
                                            <div class="text-uppercase text-success font-weight-bold text-xs mb-1"><span>Second Level</span></div>
                                            <div class="text-dark font-weight-bold h5 mb-0"><span id="secondlvl"></span></div>
                                        </div>

 

<script>
    window.addEventListener('load', function() {
    
    document.querySelector("input[name='cbParamVirtual1']").addEventListener('change', function() {
      document.getElementById('secondlvl').innerHTML = document.querySelector("span[id^='cbParamVirtual7@Data']").innerHTML;
      });
    
    }, false);
    </script>

Now I need to do the same to fetch a Virtual field value but then add it to an img tag:

<img alt="Virtual17" src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl=[@cbParamVirtual17]"/>

 

Link to comment
Share on other sites

6 hours ago, Benades said:

Hi there,

Previously @TellMeWhy helped to display values in a span tag which worked great:

<div class="col mr-2">
                                            <div class="text-uppercase text-success font-weight-bold text-xs mb-1"><span>Second Level</span></div>
                                            <div class="text-dark font-weight-bold h5 mb-0"><span id="secondlvl"></span></div>
                                        </div>

 

<script>
    window.addEventListener('load', function() {
    
    document.querySelector("input[name='cbParamVirtual1']").addEventListener('change', function() {
      document.getElementById('secondlvl').innerHTML = document.querySelector("span[id^='cbParamVirtual7@Data']").innerHTML;
      });
    
    }, false);
    </script>

Now I need to do the same to fetch a Virtual field value but then add it to an img tag:

<img alt="Virtual17" src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl=[@cbParamVirtual17]"/>

 

Put an ID to the img tag, and remove the parameter value at the end

<img id="imgelem" alt="Virtual17" src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl="/>

 

Update the code you have already, just put a name in the function

image.png.a3ca81dfb6d5c0710d2e176072d33d5e.png

 

 

Add this code to the code you have already

 document.getElementById('imgelem').src +=document.querySelector("input[name='cbParamVirtual1']").value;
  
 this.removeEventListener("change", changer);

see above for the whole code

 

what this does is append the value of Virtual1 to the src of the image.

the removeEventListener is to make sure this runs only ONCE because for some reason, the code runs twice in Chrome

Link to comment
Share on other sites

1 hour ago, Benades said:

Thanks @TellMeWhy,

Working nicely most of the time. Sometimes it doesn't fetch it but navigating away and back fixes the issue

Hmm, have you tried other browsers? You can also check F12 > Console if there are any errors when it encounters issues, it only changes values, so it should not come across issues that often

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...