printing a textarea from a form - html

I'm in the process of printing an HTML form. After checking via the internet, I am unable to print all the input. Here's what I have now:
`
<script type="text/javascript">
  function CopyElem(elem)
  {
      $('form input[type=text]').each(function() {
        $(this).attr('value', $(this).val());
      });
 
      $('form input[type=date]').each(function() {
        $(this).attr('value', $(this).val());
      });
 
      $('form input[type=checkbox]').each(function() {
        $(this).attr('checked', $(this).prop("checked"));
      });
 
  }
  function PrintElem(elem)
  {
      Popup($(elem).html());
  }
 
  function Popup(data)
  {
      var mywindow = window.open('', 'myfrm');
      mywindow.document.write('<html><head><title>Behandelformulier</title>');
      mywindow.document.write('</head><body >');
      mywindow.document.write(data);
      mywindow.document.write('</body></html>');
 
      mywindow.document.close(); // necessary for IE >= 10
      mywindow.focus(); // necessary for IE >= 10
 
      mywindow.print();
      mywindow.close();
 
      return true;
  }
`
only it does not print the content of the "input type="textarea". You won't see it in print preview either. What am I doing wrong?
I've been searching the internet for days, but can't find anything about it.

I've found the solution for my problem.
In the function CopyElem(elem) I placed
function CopyElem(elem) {
$('form textarea').each(function () {
$(this).text($(this).val());
});
}

Related

How to redirect page when select option HTML, Laravel

I need to redirect page when one of the option is selected.
<select required name="subject" id="konu" class="form-control">
<option value="" disabled>Choose Subject</option>
<option value="Ask a question">Ask a question</option>
<option value="Leave a comment">Leave a comment</option>
<option value="Where to buy">Where to buy</option>
<option value="Product Complaint">Product Complaint</option>
<option value="Other">Other</option>
<option {{ request('subject') == 'Request SDS' ? 'selected' : '' }} value="Request SDS">Request SDS</option>
<option value="Distributor">Request Distributorship</option>
</select>
I once needed this too and found that your question has already been answered.
If you're fine with using inline JavaScript, check out this answer:
https://stackoverflow.com/a/7562129/10440010
If you prefer staying off of inline, check out this answer under the same question:
https://stackoverflow.com/a/7562201/10440010
I hope this helps!
Update:
An easy way of making it work for specific options, is to make the onChange event check whether the value of the clicked option equal to something. In the snippet below, I make it work for all links starting with HTTPS.
HTML:
<select id="redirectSelect">
<option value="NoLink" disabled>Please select</option>
<option value="NoLinkEither">Option 1</option>
<option value="https://www.google.com/">External Link</option>
</select>
JavaScript:
function redirect(goto) {
var conf = confirm("Are you sure you want to go elswhere?");
if (conf && goto != '') {
window.location = goto;
}
}
var selectEl = document.getElementById('redirectSelect');
selectEl.onchange = function() {
if (this.value.startsWith('https')) {
var goto = this.value;
redirect(goto);
}
};
Hopefully this helps you enough to solve your problem. If not, leave a comment and I am glad to help!
I have a code previously woked.Here is select
<select required name="subject" id="konu" class="form-control">
                                <option value="" disabled>Choose Subject</option>
                                <option value="Ask a question">Ask a question</option>
                                <option value="Leave a comment">Leave a comment</option>
                                <option value="Where to buy">Where to buy</option>
                                <option value="Product Complaint">Product Complaint</option>
                                <option value="Other">Other</option>
                                <option {{ request('subject') == 'Request SDS' ? 'selected' : '' }}  value="Request SDS">Request SDS</option>
                                <option value="Distributor">Request Distributorship</option>
                            </select>
Here it is script.
$( document ).ready(function() {
        $("#konu").change(function(){
                var value = $("#konu").val();
                if(value=="distributor"){
                    window.location = 'be-our-distributor';
                }
            })
        });
For the second answer, the value used in your HTML differs from the value you're checking against in the JavaScript code.
In your HTML, it's Distributor and in your JavaScript code it's distributor. Mind the capital D.
the problem is on your condition. Your value is Distributor and u using distributor. Js is case sensetive so you not getting any redirection. the code should look like
$( document ).ready(function() {
$("#konu").change(function(){
var value = $("#konu").val();
if(value=="Distributor"){
window.location = 'be-our-distributor';
}
})
});

HtmlService.XFrameOptionsMode.ALLOWALL not working

Having set the XframeOptionMode, the doPost still doesn't redirect:
var REDIRECT_URL = "https://stackoverflow.com";
function doGet() {
var template = HtmlService.createTemplateFromFile("CForm.html");
template.pubUrl = ScriptApp.getService().getUrl();
var html = template.evaluate();
html.setTitle('ABCD');
return HtmlService.createHtmlOutput(html).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
function doPost(e){
SendHtmlMail(e);
return redirect().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
function redirect() {
return HtmlService.createHtmlOutput(
"<script>window.top.location.href=\"" + REDIRECT_URL + "\";</script>"
);
}
The console error still remains
Refused to display 'https://script.google.com/macros/s/AKfycbyb3wh57wgW30KV8faQNqNXSDQ_zu8w3BR-_8kVwUbI/dev' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
Relevant part of the HTML
<form class="container" id="main_form" method="post" action="<?= pubUrl ?>">
<div class="form-group">
<label>Business Name</label>
<input type="text" class="form-control" name="BusinessName" id="name" placeholder="Name of Upload" readonly>
</div>
<div class="form-group">
<label>Month and Year of Incorporation</label>
<input type="date" class="form-control" name="MonthandYearofIncorporation">
</div>
<input class="btn btn-md btn-success" type="submit" value="Apply for Carbon"/>
</form>
Though, manually pasting (hardcoding) the /exec url version of the script seems to alleviate the issue, I prefer not to.
I dropped the doPost and redirect function. Now my html now has script like:
<html>
    ...
    <body>
        ... First page ...
... Second page ...
        <form class="container d-none" id="main_form" method="post" action="<?pubUrl?>" onsubmit="submitter(this);">
   
            <div class="form-group">
                <label>Business Name</label>
                <input type="text" class="form-control" name="BusinessName" id="name" placeholder="Name of Upload" readonly>
            </div>
   
            <div class="form-group">
                <label>Month and Year of Incorporation</label>
                <input type="date" class="form-control" name="MonthandYearofIncorporation" required>
            </div>
            ... A very long form
            <input class="btn btn-md btn-success" type="submit" value="Apply for Carbon"/>
        </form>
       ...
    </body>
    <script>
      //...
      function submitter(data_process){
        // Run server-side function when submitted.
        google.script.run
            .withSuccessHandler(function(){
              //alert('Thank You!!! Your application has been received');
              window.top.location.replace("https://stackoverflow.com");
            })
            .withFailureHandler(function(e){
              alert("Unable to submit your application. Please contact us.");
              })
            .SendHtmlMail(data_process); // Server-side form processing    
      }
    </script>
</html>
ScriptApp.getService().getUrl()
returns you an Url of type
https://script.google.com/macros/s/XXX/dev
instead of
https://script.google.com/macros/s/XXX/exec,
so the developper version instead of the published version.
The former is subjected to some restrictions:
This URL can only be accessed by users who have edit access to the
script. This instance of the app always runs the most recently saved
code — not necessarily a formal version — and is intended for quick
testing during development.
See also here.
If you change dev to exec this should solve your issue.
UPDATE:
Either ScriptApp.getService().getUrl() gives you the dev or exec URL depends on how you deploy the WebApp.
When you deploy as a new version you have the option to
"Test web app for your latest code":
this will give you the dev version.
If you instead run the WebApp by copy-pasting the
Current web app URL into your browser:
your doGet() function will automatically retrieve the correct exec URL with ScriptApp.getService().getUrl().

Can't find Pi Point after create

I have C# application that creates a new Pi Point using the code based on 
PI-AF-SDK-Basic-Samples/CreatePIPointsExample.cs at master · osisoft/PI-AF-SDK-Basic-Samples · GitHub 
The point seems to be created ok - here's a screen grab following a tag search in SMT:
My problem is, when my same C# application searches for the newly created Pi Point is doesn't find it.
The code for the search is as follows:
       
private static List<PIPoint> GetPiPoints(PIServer piServer)
        {
            var criteria = GetCriteria("61");
            var foundPoints = PIPoint.FindPIPoints(piServer, criteria).ToList();
            criteria = GetCriteria("63");
            foundPoints.AddRange(PIPoint.FindPIPoints(piServer, criteria).ToList());
            criteria = GetCriteria("64");
            foundPoints.AddRange(PIPoint.FindPIPoints(piServer, criteria).ToList());
            return foundPoints;
        }
private static List<PIPointQuery> GetCriteria(string location)
        {
            List<PIPointQuery> criteria = new List<PIPointQuery>();
            PIPointQuery whereClause1 = new PIPointQuery(PICommonPointAttributes.Location1, OSIsoft.AF.Search.AFSearchOperator.Equal, location);
            PIPointQuery whereClause2 = new PIPointQuery(PICommonPointAttributes.PointSource, OSIsoft.AF.Search.AFSearchOperator.Equal, "o");
            criteria.Add(whereClause1);
            criteria.Add(whereClause2);
            return criteria;
        }
So, my understanding is that this should find all points that have a "location1" attribute value of 61, 63 or 61 AND a "pointSource" of "o" - I have tried uppercase and lower case "o"
From the screenshot, you can see that this is the case for the newly created "Kuba_99x" tag yet it is not found in the search, although thousands of other existing tags are.
Any ideas where I went wrong please?
The Pi code was actually fine. Problem was, my code was filtering the newly created record after the selection.
Location1 is stored as an Int32 on the PI Data Archive. The location parameter needs to be an int instead of string.
Further questions will be addressed at OSIsoft PI Square since you also have a post there.

Google chart x axis with decimal places

I'm attempting to create a basic google chart.
X axis is a time, y axis is a value.
Data is formatted as so:
<html>
<head>
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['line']});
    google.setOnLoadCallback(drawChart);
    function drawChart() {
      var data = new google.visualization.DataTable();
      data.addColumn('number', 'Time');
      data.addColumn('number', 'Yesterday');
      data.addColumn('number', 'Today');
      data.addColumn('number', 'TwoDayAgo');
      data.addRows([
        [01.00,  37.8, 80.8, 41.8],
        [02.00,  30.9, 69.5, 32.4],
        [03.00,  25.4,   57, 25.7],
        [04.00,  11.7, 18.8, 10.5],
        [05.00,  11.9, 17.6, 10.4]
      ]);
      var options = {
        chart: {
          title: 'Results',
          subtitle: 'Comparison'
        },
        width: 900,
        height: 500
      };
      var chart = new google.charts.Line(document.getElementById('linechart_material'));
      chart.draw(data, options);
    }
  </script>
</head>
<body>
  <div id="linechart_material"></div>
</body>
</html>
Note the decimal places in the data table.
If I remove the decimal places it will work om
However the chart does not show?

Google Chrome crashing on launch, OS X Yosemite Public Beta 2

Just recently updated to the 2nd release of OS X Yosemite's public beta. A few hours into using it, I had Chrome crash, and refuse to start up subsequently. The strange thing is, Eclipse isn't working now either, and both are throwing similar crash reports (Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000000bf001cc for both programs).
I'm attaching part of the crash report - I'd greatly appreciate it if someone could enlighten me as to how I can possibly solve this issue.
TIA!
-Karim
Process:               Google Chrome [517]
Path:                  /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Identifier:            com.google.Chrome
Version:               36.0.1985.143 (1985.143)
Code Type:             X86 (Native)
Parent Process:        ??? [1]
Responsible:           Google Chrome [517]
User ID:               501
Date/Time:             2014-08-23 23:20:13.984 +0300
OS Version:            Mac OS X 10.10 (14A329r)
Report Version:        11
Anonymous UUID:        2B3EC928-2881-8966-016D-22F741C8F171
Time Awake Since Boot: 770 seconds
Crashed Thread:        0  Dispatch queue: com.apple.main-thread
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x000000000bf001cc
VM Regions Near 0xbf001cc:
    MALLOC (admin)         00000000060e4000-00000000060e5000 [    4K] ---/rwx SM=NUL  
--> 
    MALLOC_TINY            000000007a600000-000000007a800000 [ 2048K] rw-/rwx SM=PRV  
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.AppKit               0x9b902227 +[NSResponder initialize] + 18
1   libobjc.A.dylib               0x955a92c3 _class_initialize + 502
2   libobjc.A.dylib               0x955a90fe _class_initialize + 49
3   libobjc.A.dylib               0x955a90fe _class_initialize + 49
4   libobjc.A.dylib               0x955b138e lookUpImpOrForward + 117
5   libobjc.A.dylib               0x955a906e _class_lookupMethodAndLoadCache3 + 55
6   libobjc.A.dylib               0x955a50e1 objc_msgSend + 81
7   libobjc.A.dylib               0x955a9e3d call_load_methods + 760
8   libobjc.A.dylib               0x955a8f6d load_images + 63
9   dyld                           0x8fe51e6b dyld::notifySingle(dyld_image_states, ImageLoader const*) + 271
10  dyld                           0x8fe602dc ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 276
11  dyld                           0x8fe60288 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 192
12  dyld                           0x8fe60176 ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 120
13  dyld                           0x8fe603e1 ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 79
14  dyld                           0x8fe52125 dyld::initializeMainExecutable() + 183
15  dyld                           0x8fe55bad dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 2793
16  dyld                           0x8fe51232 dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 428
17  dyld                           0x8fe51047 _dyld_start + 71
Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x9b902220  ebx: 0x955a90db  ecx: 0x0000e80c  edx: 0x00000000
  edi: 0xa0999992  esi: 0xa0f06b54  ebp: 0xbff969a8  esp: 0xbff969a0
   ss: 0x00000023  efl: 0x00010286  eip: 0x9b902227   cs: 0x0000001b
   ds: 0x00000023   es: 0x00000023   fs: 0x00000000   gs: 0x0000000f
  cr2: 0x0bf001cc
  
Logical CPU:     0
Error Code:      0x00000004
Trap Number:     14
Binary Images:
   0x68000 -    0x68ff3 +com.google.Chrome (36.0.1985.143 - 1985.143) <F977D730-6DFF-3F1C-A9DA-191F9698F00E> /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
   0x6d000 -  0x45e4fbb +com.google.Chrome.framework (36.0.1985.143 - 1985.143) <BCE7F3F9-D9F4-3494-A1BB-FF0E38406F8C> /Applications/Google Chrome.app/Contents/Versions/36.0.1985.143/Google Chrome Framework.framework/Google Chrome Framework
 0x4961000 -  0x499aff7  com.apple.audio.midi.CoreMIDI (1.10 - 88) <562B7796-CAAD-3BAA-A64A-B7FB8CE0E7FA> /System/Library/Frameworks/CoreMIDI.framework/Versions/A/CoreMIDI
 0x49be000 -  0x4c22ff7  com.apple.AddressBook.framework (8.0 - 1485) <A40C801F-9BAF-379B-B530-8CAD867A1809> /System/Library/Frameworks/AddressBook.framework/Versions/A/AddressBook
 0x4dd4000 -  0x4e2cff3  com.apple.ImageCaptureCore (6.0 - 6.0) <9DEEBD46-DF75-393C-8493-9BE7F6071E54> /System/Library/Frameworks/ImageCaptureCore.framework/Versions/A/ImageCaptureCore
 0x4e5b000 -  0x4e8cff7  com.apple.securityinterface (10.0 - 55053) <060EA66C-CA71-3314-BBB2-0B8CD838B372> /System/Library/Frameworks/SecurityInterface.framework/Versions/A/SecurityInterface
 0x4ead000 -  0x4eadfff  com.apple.quartzframework (1.5 - 1.5) <F4580C44-C3FC-37EF-B373-A594987C892F> /System/Library/Frameworks/Quartz.framework/Versions/A/Quartz
Some apparently fixed the issue via this command :
sudo chown -R $USER ~/Library/Google
I had the same problem when I upgraded to Yosemite. For me, it was fixed by uninstalling and reinstalling Chrome. I don't use Eclipse, so I can't speak to how it might be resolved.
https://www.reddit.com/r/apple/comments/2n721c/temporary_fix_for_chrome_crash_in_yosemite_10102/
which is.
Put the following in a file "patch.m":
#import <AppKit/AppKit.h>
__attribute((constructor)) void Patch_10_10_2_entry()
{
NSLog(#"10.10.2 patch loaded");
}
#interface NSTouch ()
- (id)_initWithPreviousTouch:(NSTouch *)touch newPhase:(NSTouchPhase)phase position:(CGPoint)position isResting:(BOOL)isResting force:(double)force;
#end
#implementation NSTouch (Patch_10_10_2)
- (id)_initWithPreviousTouch:(NSTouch *)touch newPhase:(NSTouchPhase)phase position:(CGPoint)position isResting:(BOOL)isResting
{
return [self _initWithPreviousTouch:touch newPhase:phase position:position isResting:isResting force:0];
}
#end
Compile it:
clang -dynamiclib -framework AppKit patch.m -o patch.dylib
Use it:
env DYLD_INSERT_LIBRARIES=/path/to/patch.dylib "/path/to/Google Chrome.app/Contents/MacOS/Google Chrome"
You can't close the process but if you don't want extra dock items, leave it in a detached tmux (or similar) session.