473,587 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating form elements inside PHP Form

82 New Member
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]
Feb 26 '08 #1
4 2486
ronverdonk
4,258 Recognized Expert Specialist
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
raknin
82 New Member
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
4,258 Recognized Expert Specialist
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
Feb 26 '08 #4
raknin
82 New Member
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

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

Similar topics

1
4358
by: Anna | last post by:
Hi all. I have a javascript function that loops throught all text boxes inside a form: var elems = document.formName.elements; for(i = 0; i < elems.length; i++) { if(elems.type && elems.type.toLowerCase()=="text") do something }
1
6008
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to...
6
2819
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can some one tell me what I'm doing wrong? it looks like this: var tbl=document.tbl; var frm=document.frm; var newcell=document.createElement("TD");
2
2900
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple text instead. But I want to keep the format of my page EXACTLY the same. However, the problem is that ... 1) Javascript won't let me create say a...
4
2133
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see "TAG#") when more than 1 number (see "VLANS") is inputed into my form. QUESTION: How do I make my dynamic form have a dynamic input box(which is...
5
7396
by: Markus Ernst | last post by:
Hi I have a validation problem with a form and nested divs. I understand what the problem is, but I don't see how to fix it. This is my normal page structure, and it validates: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>
2
1871
by: jingalls | last post by:
I'm trying to modify a form so that when a user clicks a checkbox for a shorter version of the form, it will replace swap the default (long) form elements with the short version of elements, so that only the version that is selected will have its element values passed on to the next page. Currently I have two div areas set up with ids as...
6
3862
by: ashok.dhananjeyan | last post by:
Hi, Actually , I wrote one javascript to retrieve the name of the form in one particular page. what i did in this page is, <script> function checkbutton() {
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.