Click to See Complete Forum and Search --> : autogenerate text box during passing value from child window?


lting
01-08-2004, 10:13 PM
can i do script like.

when i click the edit button at the parent window(page.pgp), a window popup( anotherpage.php )

when i enter a value there, then it appears inside parent window's text box1

then when i enter another value at the children window, then at the parent window textbox2 will appear and with my second value inside

if i insert 3rd value, another textbox appear with my 3rd value inside in the parent window ...

i hope it can auto generate text box , depends on how many value i insert in the child window ..

possible?

Fang
01-09-2004, 03:19 AM
The basics:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Parent page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
//<![CDATA[
<!--
function OpenWin() {
var content='<form action="#" name="childform">'+
'<input type="text" id="newtext" /><br />'+
'<button type="text" onclick="opener.InsertField(document.getElementById(&quot;newtext&quot;).value);">Add field</button>'+
'</form>';
ChildWindow=window.open("", "newwin");
ChildWindow.document.write(content);
ChildWindow.document.close();
}
var idx=0;
function InsertField(text) {
var newField=document.createElement('input');
newField.setAttribute('id','newField'+(idx++));
newField.setAttribute('type','text');
newField.setAttribute("value", text);
document.getElementById('myform').appendChild(newField);
}
//-->
//]]>
</script>

</head>
<body>
<form action="#" id="myform">
<button type="text" onclick="OpenWin();">edit</button>
<button type="submit">submit</button>
</form>
</body>
</html>

lting
01-09-2004, 06:17 AM
i ccopy the script ..

and try to run it .. but browser said runtime errors ...

Pittimann
01-09-2004, 07:00 AM
Hi!

There's a tiny mistake in the line with the content variable.
Please try it like this:
var content='<form action="#" name="childform">'+'<input type="text" id="newtext" /><br />'+'<button type="text" onclick="opener.InsertField(document.getElementById(\'newtext\').value);">Add field</button>'+'</form>';

Cheers - Pit

Fang
01-09-2004, 12:24 PM
I used extended characters, which were ofcourse changed in the output :rolleyes: