1

I kind of need to create html page copy by clicking on button in this page, but where all <input type = 'text'... replaced with it's values.

I think, I can handle the second part, but how first to get html code? Are this ever possible?

I need this for generating html reports.
Page is shown in internal browser of my prog. The basic idea, the student see the page with inputs, then when he fill all, he press button inside HTML page, some JS handler work and send to my prog same page, but without inputs for later review for teacher.

Kosmo零
  • 4,001
  • 9
  • 45
  • 88
  • you mean you need to make a new version of a page re-loading it with the input values. With input field on new page or without? – Sergio Jun 01 '13 at 19:00
  • Maybe this SO question would help: http://stackoverflow.com/questions/982717/how-do-i-get-the-entire-pages-html-with-jquery – DannyB Jun 01 '13 at 19:01
  • yes it is could you please share your html code – Muhammad Bekette Jun 01 '13 at 19:01
  • Page is shown in internal browser of my prog. The basic idea, the student see the page with inputs, then when he fill all, he press button inside HTML page, some JS handler work and send to my prog same page, but without inputs. This is kind of creating report. – Kosmo零 Jun 01 '13 at 19:04

3 Answers3

2

If you want to get the html for the body of the document, use this:

document.body.innerHTML

You can then modify it as needed and change it:

document.body.innerHTML = ... modified html ...

There are better ways to achieve the result though, like manipulating the DOM with jQuery.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
  • could I use document.innerHTML to receive whole page starting from html tag? I am kind of far from work place where I can check in steps mode – Kosmo零 Jun 01 '13 at 19:06
  • @Kosmos, `document` itself does not have `innerHTML`. The closest thing is `document.firstChild.innerHTML` which will be everything inside `html` tags. – Samuel Neff Jun 01 '13 at 19:08
  • Thank you, this should be enough for me – Kosmo零 Jun 01 '13 at 19:09
  • @SamuelNeff, does the input values get collected by `document.body.innerHTML` before they are submitted? – Sergio Jun 01 '13 at 19:17
  • I think I will do simple string replace of inputs with it's values. I have an array where all inputs is stored, so when I got html page, I will run through it's tags and replace what needed. – Kosmo零 Jun 01 '13 at 19:21
2

You can use document DOM element and serialize it:

(new XMLSerializer()).serializeToString(document);

for cross-browser compatibility see this post

Community
  • 1
  • 1
LZR
  • 948
  • 10
  • 28
1

If you have a <form> you can post to the same page adding ?post=1 to the action.

Then in the php

if ($_GET["post"]==1) { 
//same table or div structure getting the values submitted by the form
}

Do you know how to do it? was this you needed?

Sergio
  • 28,539
  • 11
  • 85
  • 132
  • Thank you, but this is for PHP, but in my prog there is only pure html / js is loaded, so I needed solution for this. Sorry for not full explaining this in base question – Kosmo零 Jun 01 '13 at 19:14