SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Get the Posted Value ??

    I have a form with select options
    and when the user change from the select menu,tehh Input is appearing

    The main problem that each time i submit the form
    the last input only appears becuase they have the same name
    thats my code
    PHP Code:
    <script type="text/javascript"><!--
    var lastDiv = "";
    function showDiv(divName) {
        // hide last div
        if (lastDiv) {
            document.getElementById(lastDiv).className = "hiddenDiv";
        }
        //if value of the box is not nothing and an object with that name exists, then change the class
        if (divName && document.getElementById(divName)) {
            document.getElementById(divName).className = "visibleDiv";
            lastDiv = divName;
        }
    }
    //-->
    function hideDiv() {
            document.getElementById('4').className = "hiddenDiv";

    }
    </script>

    <style type="text/css" media="screen">
    <!--
    .hiddenDiv {
        display: none;
        }
    .visibleDiv {
        display: block;
        border: 1px grey solid;
        }

    -->
    </style>

    </head>

    <body>
    <?php 
    print_r
    ($_POST['one']);
    ?>
    <form name="script_display" method="post" action="">
    <table cellpadding="0" cellspacing="0" border="0" width="600">
        <tr>

            <!-- ===== START select-list column START ===== -->
            <td width="300" valign="top">
            LIST A
            <select name="selectlista" onchange="showDiv(this.value);hideDiv()">
                <option value="">Select</option>
                <option value="1">Display Script A1 </option>
                <option value="2">Display Script A2 </option>
                <option value="3">Display Script A3 </option>
            </select>

            </td>
            <!-- ===== END select-list column END ===== -->

            <!-- ===== START script column START ===== -->
            <td width="300" valign="top">
            <div id="1" class="hiddenDiv">
                <input name="one[]" type="text" value="one"/>        
            </div>
            <div id="2" class="hiddenDiv">
                <input name="one[]" type="text" value="two"/>        
            </div>
            <div id="3" class="hiddenDiv">
                <input name="one[]" type="text" value="three"/>        
            </div>
                            
            <div id="4" class="visibleDiv">
                <input name="one[]" type="text" value="four"/>        
            </div>
            </td>
        
            <!-- ===== END script column END ===== -->
            
        </tr>
    </table>
    <input name="submit" type="submit" />
    </form>

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the name so you don't have duplicate form elements.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank u
    i changed the name and put this
    PHP Code:
    <?php 
    $num
    ='';
    if(
    $_POST['selectlista']=='1'){echo $num=$_POST['one1'];}
    if(
    $_POST['selectlista']=='2'){echo $num=$_POST['one2'];}
    if(
    $_POST['selectlista']=='3'){echo $num=$_POST['one2'];}

    ?>


Bookmarks

Posting Permissions

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