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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Button write more than once?

    PHP Code:
    <body>
    <?php
    //if (isset($_POST[''])) {

    //}
    ?>

    <form name="tbCreate" method="post">
    Table name:<br />
    <input type="text" name="tableName"><br />
    <?php 
    if (isset($_POST['addColumn'])) {
        echo 
    "Column Name: <input type=\"text\" name=\"columnName[]\"><br />";
    }
    ?>
    <input type="submit" name="addColumn" value="Add Column">
    </form>
    </body>
    Is there a way that the addColumn button can be clicked more than once, so that I can get more columnName fields?

  • #2
    New Coder
    Join Date
    Jul 2009
    Posts
    37
    Thanks
    1
    Thanked 1 Time in 1 Post
    Rather than going to the server each time you would be better using javascript. Each time the btnAddParam button is clicked it will get the div with id additionalParams and add the new item to the content


    Code:
    <div id="additionalParams">
    </div>
    <input name="btnAddParam" type="button" alt="Add Param" value="Add Param" onclick="addParameter();"/>
    
    <script language="JavaScript" type="text/javascript">
    function addParameter() {
    $('additionalParams').update($('additionalParams').innerHTML + <input type="text" id="requestParamName" name="requestParamName[]"/>');
    }
    </script>
    Last edited by RossMcCaughrain; 01-20-2010 at 05:08 PM. Reason: Adding script tags

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Problem with JavaScript though is that some users may have it disabled.

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    37
    Thanks
    1
    Thanked 1 Time in 1 Post
    Sure its a possiblility. Problem with doing it via server calls however is that you will need to store all the currently entered user info in every field for displaying again on reload etc. I know I would be peeved if i had entered 30 column names etc then clicked add button and it reloaded with 31 columns all blank.

    I would use Javascript as default, do a check to see if they have javascript and if not present them with a form saying how many columns do you need? Then post it to itself and use a php loop to create the correct number of columns.


  •  

    Posting Permissions

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