By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Manipulating form elements inside PHP Form

P: 82
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="jetsExperience" style="width:150px">
<option value="1" selected="selected">Novice</option>
<option value="2">Intermidate</option>
<option value="3">Expert</option>
</select>
Driver, own the following car:
<select name="manufacture" style="width:150px">
<option value="Fiat">Fiat</option>
<option value="Honda">Honda</option>
<option selected value="Volvo">Volvo</option>
</select>
<select name="model" style="width:150px">>
<option value="130">130</option>
<option value="140">140</option>
<option selected value="150">150</option>
<option value=""></option>
</select>
<input type="button" name="groovybtn1" class="addButton" value="ADD" title=""> <br />[/HTML]
Feb 26 '08 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 26 '08 #2

P: 82
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.
Feb 26 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
Yes, you can populate your HTML drop downs etc. using PHP.
Something like e.g.[php]echo '<select name="mysel">';
while ($row=mysql_fetch_assoc($result)) {
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
Feb 26 '08 #4

P: 82
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:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. /* 
  4. - Function to return the Country list as an array 
  5. - The array can be generated from a database resultset 
  6. */ 
  7. function getCountryList() 
  8.   // Country List array 
  9.   $countryList    = array ( 
  10.                           '1' => 'Bangladesh', 
  11.                           '2' => 'USA', 
  12.                           '3' => 'UK' 
  13.                           ); 
  14.  
  15.   return $countryList; 
  16.  
  17. /* 
  18. - Function to return the City list as an array 
  19. - Country ID is used to generate the city list 
  20. */ 
  21. function getCityList($countryId) 
  22.   // City list array 
  23.   // First key of the array is the Country ID, which holds an array of City list 
  24.   $cityList       = array ( 
  25.                           '1' => array ('Dhaka', 'Chittagong', 'What else'), 
  26.                           '3' => array ('London', 'Cannot Remember'), 
  27.                           '2' => array ('Washington', 'N.Y.', 'etc') 
  28.                           ); 
  29.  
  30.   return $cityList[$countryId]; 
  31. ?> 
  32.  
  33. <form action="" name="populate"> 
  34.  
  35. <?php 
  36. // Retrieving the country list 
  37. $countryList  = getCountryList(); 
  38. if (!empty($countryList)) 
  39.   // Generating the country drop down menu 
  40.   echo "<select onChange='reload(this.form)' name='countryList'>"; 
  41.   foreach ($countryList as $key => $value) 
  42.   { 
  43.     echo "<option value='$key'"; 
  44.  
  45.     if ($countryId == $key) 
  46.       echo "selected"; 
  47.  
  48.     echo ">$value</option>"; 
  49.   } 
  50.   echo "</select>"; 
  51. // Setting the variable if the country is selected for its city list 
  52. //@$countryId  = $_GET['countryId'];
  53. // I want to build the city list based on the selection of the countryId
  54.  
  55. // Retrieving the city list if a country is selected 
  56. $cityList   = ($countryId) ? getCityList($countryId) : null; 
  57.  
  58.  
  59. if (!empty($cityList)) 
  60.   // Generating the city drop down menu if a country is selected 
  61.   echo "<select name='cityList'>"; 
  62.   foreach ($cityList as $key => $value) 
  63.   { 
  64.     echo "<option value='$key'>$value</option>"; 
  65.   } 
  66.   echo "</select>"; 
  67.  
  68. ?> 
  69. </form>
  70.  
  71.  
Feb 27 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.