Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    add a new check box when a button is pressed??

    Hi ,
    I was trying to add a check box dynamically when a button is pressed.
    The check box contains title and a textbox for the user to enter data.
    For example , when the user hits addnew button , a new check box (title-name)
    with a textbox for entering name should appear on the form.
    Please help
    thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The check box contains title and a textbox for the user to enter data.
    Sorry, this is not clear, though you could find a lot examples for dynamic form by searching this forum, see
    http://www.google.com/search?q=site%...m+dynamic+form
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    tech99sri (05-02-2008)

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Sorry, this is not clear, though you could find a lot examples for dynamic form by searching this forum, see
    http://www.google.com/search?q=site%...m+dynamic+form


    there's a check box and a text box .
    These should be visible when we click a button.
    Please provide any example code .I am not able to find anything .
    thanks

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    See if this basic example help
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function Add()
    {
    var checkbox=document.createElement('input');
    var inps=document.createElement('input');
    var output=document.getElementById('output');
    checkbox.type='checkbox';
    inps.type='text';
    inps.name='textboxname';
    checkbox.name='checkname';
    output.appendChild(checkbox);
    output.appendChild(inps);
    output.appendChild(document.createElement('br'));
    }
    </script>
    </head>
    <body>
    <span id="output"></span>
    <input type="button" value="Add" onclick="Add()">
    </body>
    </html>
    Last edited by rangana; 05-01-2008 at 07:32 AM.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    tech99sri (05-02-2008)

  • #5
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thankyou ,
    I really appreciate your help .I was able to get the checkbox and the textbox when the click the add button.
    How do I set the name (text infront of the textbox or the check box example firstname)
    Sorry to ask a simple question ,I am new to java.
    thanks

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Posts
    114
    Thanks
    4
    Thanked 3 Times in 3 Posts
    First of all, you are using javascript, not Java. They are as different as apples and oranges. Microsoft ripped off Java's name when making javascript in hopes of increased popularity. Java is a desktop language, javascript is a web language.

    Sorry, it's just something that bothers me.

    Looks like if you are just trying to set the text between the two elements you can just use document.write. Just put it here...
    Code:
    ...
    output.appendChild(checkbox);
    document.write("WHATEVER YOU WANT HERE!");
    output.appendChild(inps);
    output.appendChild(document.createElement('br'));
    ...
    However you seem fairly new to coding in general, I really suggest picking up a book if you are going to be doing this for any length of time whatsoever, it will really help out in the long run.

  • Users who have thanked JoWiGo for this post:

    tech99sri (05-02-2008)

  • #7
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    problem with document.write()

    hi,
    I couldnot display the name of the check box and the text box
    this is the code:

    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%><div id="divform" style="position:absolute;z-index:2; ">
    <form name="frm" id="frm" action="../wait.html" method="post" >
    <div id="set1" style="position:absolute; left:65px;top:146px;" style = "hidden">
    <span id="output"></span>
    <input type="button" value="Add" onclick="Add()">
    <script type="text/javascript">
    function Add()
    {
    var inps=document.createElement('input');
    var inpstext=document.createElement('input');
    var value=document.createElement('input');
    document.write("WHATEVER YOU WANT HERE!");
    inps.type='checkbox';
    inps.name='checkname';

    document.getElementById('output').appendChild(inps);
    document.getElementById('output').appendChild(inpstext);
    }

    </script>
    </div>

    </form>

    When I press the add button just the text is displayed but the check box or the text filed is not displayed (they work fine without the document.write("WHATEVER YOU WANT HERE!")
    I will have to read some books in java script after this task is done , cos I dont have much time.
    thanks

  • #8
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    First of all, you are using javascript, not Java. They are as different as apples and oranges. Microsoft ripped off Java's name when making javascript in hopes of increased popularity. Java is a desktop language, javascript is a web language.
    sorry, this is not correct, javascript was developed by netscape. the rip-off you are trying to refer to is J#, microsoft's proprietary take on the java language for better integration into windows.
    http://faculty.frostburg.edu/cosc/ht...tPL/PL_Net.htm
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • Users who have thanked mjlorbet for this post:

    tech99sri (05-02-2008)

  • #9
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Quote Originally Posted by tech99sri View Post
    Thankyou ,
    I really appreciate your help .I was able to get the checkbox and the textbox when the click the add button.
    How do I set the name (text infront of the textbox or the check box example firstname)
    Sorry to ask a simple question ,I am new to java.
    thanks
    This should do it for you:
    Code:
    <form name="frm" id="frm" action="../wait.html" method="post" >
    <div id="set1" style="position:absolute; left:65px;top:146px;" style = "hidden">
    <span id="output"></span>
    <input type="button" value="Add" onclick="Add()">
    <script type="text/javascript">
    function Add()
    {
    var checkbox=document.createElement('input');
    var inps=document.createElement('input');
    var label=document.createElement('label');
    var output=document.getElementById('output');
    checkbox.type='checkbox';
    label.innerHTML='Firstname';
    label.style.paddingRight='10px';
    inps.type='text';
    inps.name='textboxname';
    checkbox.name='checkname';
    output.appendChild(checkbox);
    output.appendChild(label);
    output.appendChild(inps);
    output.appendChild(document.createElement('br'));
    }
    </script>
    </div>
    </form>
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    tech99sri (05-02-2008)

  • #10
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    How do I access the data in the textboxes in to collection object

    Hi ,
    I am really very thankful for all your help.
    How do I access the data in the textbox in to a collection object.
    Please provide a solution
    thanks

  • #11
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    My apologies, but I can't understand it.

    ...What do you mean by collection object?..are you referring to an array?..
    ...Could you explain a little bit further
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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