...

View Full Version : retreiving content of a div



Sgrdaddy
04-10-2003, 03:38 PM
hey guys and gals,

i'v got a big problem...

i need to retreive the content, including elements from a div.

is this possible? i know that you can make a page editable. but can you "copy/paste" total content...

this is how it should be:

in a page is a div with id=content. In this div are all different form elements, with values. Below this div is a button, when you press that button a popup appears with the contents (all form elements + values) of the previous div.

can this be done...

beetle
04-10-2003, 03:39 PM
Specify what you mean when you say "content".

HTML content?
Form data?
Element list?

???

Sgrdaddy
04-10-2003, 03:45 PM
all of the above :)

like everything that is in that div : tables, form elements like textfields checkbuttons,...

<div id="content">
bladibladibla
<form>
<input type="textfield" value="bladibla">
<input type="checkbox" value="true">
</form>
<table><tr><td>hadiho</td></tr></table>
</div>

<input type=button value="submit">


when pressing that button a popup must appear with everything thats in the div


popup:

bladibladibla
<form>
<input type="textfield" value="bladibla">
<input type="checkbox" value="true">
</form>
<table><tr><td>hadiho</td></tr></table>

beetle
04-10-2003, 04:05 PM
Oh. Uhh, quick and dirty solution.
<html>
<head>
<title>Test</title>

<script type="text/javascript">

function openWithContent( id, outer )
{
var prop = ( outer ) ? 'outerHTML' : 'innerHTML';
var myWin = window.open( '', 'myWin', 'width=500,height=400' );
var d = myWin.document;
d.write( '<html><head><title>Blah</title></head><body>' );
d.write( document.getElementById( id )[prop] );
d.write( '</html>' );
}

</script>


</head>
<body onload="">
<h1>Test</h1>
<div id="blah">
<form>
Name <input type="text" name="" />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
<p>
blah blah
</p>
</div>
<input type="button" value="Try it" onclick="openWithContent( 'blah', 0 )" />
</body>
</html>

Sgrdaddy
04-11-2003, 07:38 AM
wow thx m8

U ROCK

Sgrdaddy
04-11-2003, 07:48 AM
hmmm can you explain me something

What does that prop ?

both onclick="openWithContent( 'blah', 1 );" and onclick="openWithContent( 'blah', 0 );" work

beetle
04-11-2003, 07:51 AM
A true value (1) will get the contents of the DIV and the div itself.

outerHTML vs. innerHTML

Sgrdaddy
04-11-2003, 07:53 AM
aaaaaaaah ok :)

THX !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum