Manipulating form elements inside PHP Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raknin
    New Member
    • Oct 2007
    • 82

    Manipulating form elements inside PHP Form

    Hi,

    I built a form in php that contains some check boxes and drop-down boxes and a Add button. What I want to do is manipulating the check box state (checked and uncheked state) in order to disable button and other elemnets form.
    My question is how can I manipulate the formm element with out submiting it. The codeis display below.

    [HTML]<input name="cars id="cars" type="checkbox" value="cars"> Airplanes
    , I am
    <select name="jetsExper ience" style="width:15 0px">
    <option value="1" selected="selec ted">Novice</option>
    <option value="2">Inter midate</option>
    <option value="3">Exper t</option>
    </select>
    Driver, own the following car:
    <select name="manufactu re" style="width:15 0px">
    <option value="Fiat">Fi at</option>
    <option value="Honda">H onda</option>
    <option selected value="Volvo">V olvo</option>
    </select>
    <select name="model" style="width:15 0px">>
    <option value="130">130 </option>
    <option value="140">140 </option>
    <option selected value="150">150 </option>
    <option value=""></option>
    </select>
    <input type="button" name="groovybtn 1" class="addButto n" value="ADD" title=""> <br />[/HTML]
    Last edited by raknin; Feb 26 '08, 12:47 PM. Reason: some spelling mistakes
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    A form is always a HTML form, not a PHP forum. PHP just generates it.

    When would you like to manipulate these elements: at the moment an item is selected or when the add button is clicked, or how else? without submitting.

    I guess that you can achieve what you want using JavaScript, since you do not want a submit.

    Ronald

    Comment

    • raknin
      New Member
      • Oct 2007
      • 82

      #3
      Originally posted by ronverdonk
      A form is always a HTML form, not a PHP forum. PHP just generates it.

      When would you like to manipulate these elements: at the moment an item is selected or when the add button is clicked, or how else? without submitting.

      I guess that you can achieve what you want using JavaScript, since you do not want a submit.

      Ronald
      Hi ronald,

      1. The issue is that I am creating a PHP register page, since I don't want that the registration information will go from the client not iencrypted(I ran it on the server). So The HTML above is a part of the php file registration form. Can it be done. in the beginig of the PHP file their is a php section that process the sent inofrmation and after word there is a HTML form document.
      2. Can I send throught the same php page in the html part a query to the DB and populte a dropdown list with the quesry result. I run all the calculation on the server.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Yes, you can populate your HTML drop downs etc. using PHP.
        Something like e.g.[php]echo '<select name="mysel">';
        while ($row=mysql_fet ch_assoc($resul t)) {
        echo '<option value="'.$row['item'].'">'.$row['item'].'</option>';
        }
        echo '</select>';[/php]But it would be a lot easier for us to see what code you are talking about and show what you have done so far.

        Ronald
        Last edited by ronverdonk; Feb 26 '08, 11:39 PM. Reason: enhancing reply

        Comment

        • raknin
          New Member
          • Oct 2007
          • 82

          #5
          Thanks ronald but I already figure it out my self. Now I have a different problem that I amworking onit. If I select a value from the list and want to manipulated it for building second list that depend on the slection of the first list before the form is sunbmitted. Any clue howit can be done.

          Here is the code that I have:

          Code:
          <?php 
          
          /* 
          - Function to return the Country list as an array 
          - The array can be generated from a database resultset 
          */ 
          function getCountryList() 
          { 
            // Country List array 
            $countryList    = array ( 
                                    '1' => 'Bangladesh', 
                                    '2' => 'USA', 
                                    '3' => 'UK' 
                                    ); 
            
            return $countryList; 
          } 
          
          /* 
          - Function to return the City list as an array 
          - Country ID is used to generate the city list 
          */ 
          function getCityList($countryId) 
          { 
            // City list array 
            // First key of the array is the Country ID, which holds an array of City list 
            $cityList       = array ( 
                                    '1' => array ('Dhaka', 'Chittagong', 'What else'), 
                                    '3' => array ('London', 'Cannot Remember'), 
                                    '2' => array ('Washington', 'N.Y.', 'etc') 
                                    ); 
            
            return $cityList[$countryId]; 
          } 
          ?> 
          
          <form action="" name="populate"> 
          
          <?php 
          // Retrieving the country list 
          $countryList  = getCountryList(); 
          if (!empty($countryList)) 
          { 
            // Generating the country drop down menu 
            echo "<select onChange='reload(this.form)' name='countryList'>"; 
            foreach ($countryList as $key => $value) 
            { 
              echo "<option value='$key'"; 
              
              if ($countryId == $key) 
                echo "selected"; 
              
              echo ">$value</option>"; 
            } 
            echo "</select>"; 
          } 
          // Setting the variable if the country is selected for its city list 
          //@$countryId  = $_GET['countryId'];
          //[B] I want to build the city list based on the selection of the countryId[/B]
             
          // Retrieving the city list if a country is selected 
          $cityList   = ($countryId) ? getCityList($countryId) : null; 
          
          
          if (!empty($cityList)) 
          { 
            // Generating the city drop down menu if a country is selected 
            echo "<select name='cityList'>"; 
            foreach ($cityList as $key => $value) 
            { 
              echo "<option value='$key'>$value</option>"; 
            } 
            echo "</select>"; 
          } 
          
          ?> 
          </form>

          Comment

          Working...