php


Reading and printing user inputs in HTML in PHP


I have got a form (php in html or the other way around). Once user selects an option in a drop down list, it would get the input value and create a few text boxes. It seems like I have to use onchange(). How do I read the input and perform logics within the script inself? Instead of opening another .php script?
Currently this is what I have.
<?php
$tables = $_POST["tables"];
?>
<html>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Table Name: <div id="tables">
<select name="tables">
<option value="Applications">Application</option>
<option value="Device">Device</option>
</select>
</div>
</form>
<?
echo "".$tables."";
?>
You can't interact with PHP once the HTML is sent to the browser without either
Refreshing the page, or
Using AJAX (JavaScript).
If you know the options in the <select> beforehand (which it seems like you do), you should write some JavaScript to accomplish what you need. Here is a simple example using jQuery.
$('#tables_select').change(
function( eventObject ){
alert('You chose ' + $(this).val());
switch( $( this ).val())
{
case 'Applications':
$('#tables').append('<input type="text" name="application_name" value="Enter an application name" />"');
break;
case 'Device':
$('#tables').append('<input type="text" name="device_name" value="Enter a device name" />"');
break;
}
}
);
You will need to add additional logic to remove the inserted elements if the user changes their choice, and to insert the correct <input> elements when the page first loads, but it is a good starting point.
if you want to add any input type ... here is the demo demo with code
you use following method.
<form method="post" action="<?php echo $PHP_SELF;?>" onChange="return createTxtbox()">
Table Name: <div id="tables">
<select name="tables">
<option value="Applications">Application</option>
<option value="Device">Device</option>
</select>
</div>
<span id="fooBar"> </span>
</form>
then write javascript,
<SCRIPT language="javascript">
function createTxtbox() {
var type="text";
//Create an input type dynamically.
var element = document.createElement("input");
//Assign different attributes to the element.
element.setAttribute("type", type);
element.setAttribute("value", type);
element.setAttribute("name", type);
var foo = document.getElementById("fooBar");
//Append the element in page (in span).
foo.appendChild(element);
}
</SCRIPT>

Related Links

php - How to show a pop-up thank you message instead of another page
How to make a username entries required to be unique with php
Adding a link to click a new button on the form [duplicate]
How to bypass CloudFlare rocket script if wp_enqueue_script is used to add scripts?
Image path upload and displaying image in mysql
fusionchart in php are not showing
php built in webserver not reacheable with ip:port via network cable
I cant get value of the radio button Except first radio button
Edit iframe content using PHP, and preg_replace()
PMPRO Wordpress plugin Membership Cancellation Errors (stripe)
Android HttpURLConnection Post Data, PHP App Server can't receive data
compare todays date with the date in the mysql table using codeigniter
Get all possible combinations without duplicates
how to upload to files to amazon EC2
Getting the top scores, but remove duplicate users (SQL)
Explode a string after 5 spaces and 2 new lines in a string in PHP

Categories

HOME
xpath
spring-data
barcode-scanner
long-integer
code-formatting
initialization
visual-studio-2010
twitter-fabric
elisp
openflow
azure-data-lake
graphql-js
polymer-2.x
spring-security-oauth2
yeoman-generator-angular
rangy
buffer
bootstrap-switch
android-externalstorage
jquery-select2-4
webstore
temperature
vertica
web-deployment
cpu-usage
adminlte
nurbs
data-collection
android-service
ccavenue
envoy
winsock
tightvnc
python-2.x
payeezy
markov-chains
adminer
netstat
nsuserdefaults
unification
xll
django-smart-selects
sspi
export-to-pdf
jacoco-maven-plugin
newtons-method
klee
data-uri
zend-form
destroy
flume-twitter
autorelease
cordova-ios
solr-query-syntax
sesame
mechanicalturk
business-rules
libharu
logical
dmarc
spring-mongo
openseadragon
powerpoint-2013
uibinder
mnesia
gravatar
taco
grinder
blockquote
phpredis
flow-js
sablecc
signed
fileshare
miglayout
preorder
pre
principalcontext
libxml-js
tnt4j
lru
chefspec
ntlmv2
office-app
tridion-2011
idispatch
xcode4.5
zend-pdf
wndproc
popup-blocker
dropshadow
netstream
differentiation
aggregator
urchin
tabbarcontroller
ixmldomdocument
fxruby
.net-client-profile
accumulator
ntruencrypt
objectinstantiation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App