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.

4
  • 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? Commented Jun 1, 2013 at 19:00
  • Maybe this SO question would help: stackoverflow.com/questions/982717/… Commented Jun 1, 2013 at 19:01
  • yes it is could you please share your html code Commented Jun 1, 2013 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. Commented Jun 1, 2013 at 19:04

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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
@Kosmos, document itself does not have innerHTML. The closest thing is document.firstChild.innerHTML which will be everything inside html tags.
Thank you, this should be enough for me
@SamuelNeff, does the input values get collected by document.body.innerHTML before they are submitted?
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.
2

You can use document DOM element and serialize it:

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

for cross-browser compatibility see this post

Comments

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?

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.