www.webdeveloper.com
Results 1 to 5 of 5

Thread: autogenerate text box during passing value from child window?

  1. #1
    Join Date
    Dec 2003
    Location
    Malaysia
    Posts
    206

    Question autogenerate text box during passing value from child window?

    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?

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The basics:
    Code:
    <!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>

  3. #3
    Join Date
    Dec 2003
    Location
    Malaysia
    Posts
    206
    i ccopy the script ..

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

  4. #4
    Join Date
    Nov 2003
    Location
    Aachen, Germany
    Posts
    4,090
    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

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    I used extended characters, which were ofcourse changed in the output

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles