0

I want to log a javascript-calculated result div from an anonymous little survey produced via a Wordpress plugin.

The html produced is:

<div ref="fieldname57_1" class="cff-summary-item">
<span class="summary-field-title cff-summary-title">Yearly costs</span>       
<span class="summary-field-value cff-summary-value">£120</span></div> 
(...)

It is rendered as

Yearly costs: £120
Monthly costs: 10

because the css has, for example:

fbuilder .cff-summary-title:after {
    content: ': ';
}

I can grab and post the text and log it with nginx with a basic jquery post handler like this:

var stuff = jQuery('#fieldname66_1').text();
jQuery.post( "/formpost.txt", { name: "result", value: stuff } );

but everything comes out as Yearly costs£120Monthly costs£10

I can grab jQuery('#fieldname66_1').html() but then I have the html to process.

I could do back-end processing - I'm a node-newbie but have it installed and I can see various npm packages which MIGHT be co-erced in processing the output.

I'm aware of jQuery's makeArray and toArray functions, but these still give me the html. I could use .next() to traverse my way through the spans and get the results into an array.

But ... am I missing a trick here?

  • When I say "log", it doesn't need to be "per line" log format -

  • I'd still to log the entire div "as rendered". I can't change the plugin code, even if I could let's treat this as a learning tool!

  • The entire page output is javascript, rendered in-browser.

Thank you!

Community
  • 1
  • 1
digitaltoast
  • 659
  • 7
  • 23

1 Answers1

1

First off, that is terrible HTML. A table or a definition list would be better. And if you want to post that data to a server, best would be to have a form with fields.

If you want to keep it as it is, get the text of the spans separately and and join them together with a colon yourself.

Are the multiple title/value pairs in one item? If yes, what do you want to have between two title/value pairs when sending them to the server?

RoToRa
  • 37,635
  • 12
  • 69
  • 105
  • Thanks! Can't do anything about the html - yes, in an ideal world it wouldn't be like that. Looking at it again, I think the easiest way is to write a php handler that will just create an html wrapper with the relevant line of CSS, and then just display the data as a mini webpage. Horrible, I know, but small amount of data and low volume of responses make that probably the most time-cost-effective method. Still open to alternatives though! – digitaltoast Jan 01 '16 at 19:57