php


sending value from php page to selection tag using request


I want to send a value from php page that will select the value and html page show that selected value.
Here is my code:
Blood Group:
<select name="bloodgp" <?php echo($data['user_bloodgroup']==$bloodgp)?'checked':'' ?>>
<option value="A+">A+</option
<option value="B+">B+</option>
<option value="AB+">AB+</option>
<option value="O+">O+</option>
<option value="A-">A-</option>
<option value="B-">B-</option>
<option value="AB-">AB-</option>
<option value="O-">O-</option>
</select>
If you just want to send data on HTML page then it will be possible through jquery. You can use below code for your requirement.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click', '#bloodgp', function() {
var get_selected_option_value = $(this)val();
window.location = 'your_html_page_name/bloodgp=' + get_selected_option_value;
});
});
</script>
</head>
<body>
Blood Group:
<select name="bloodgp" id="bloodgp" <?php echo($data['user_bloodgroup']==$bloodgp)?'checked':'' ?>>
<option value="A+">A+</option
<option value="B+">B+</option>
<option value="AB+">AB+</option>
<option value="O+">O+</option>
<option value="A-">A-</option>
<option value="B-">B-</option>
<option value="AB-">AB-</option>
<option value="O-">O-</option>
</select>
</body>
</html>
You can get the value from URL using above code.
Above code is for your requirement. But i am suggesting you to send the value to php file instead of HTML file. it will be more feasible for you.
If you want send data to php file then you can use ajax for that. You can find the below code with ajax.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click', '#bloodgp', function() {
var get_selected_option_value = $(this)val();
window.location =
$.ajax({
url: 'your_page_page_name.php',
type: 'POST',
dataType: 'json',
data: {bloodgp: get_selected_option_value},
})
.success(function(response) {
console.log("you have successfully sended the data");
})
});
});
</script>
</head>
<body>
Blood Group:
<select name="bloodgp" id="bloodgp" <?php echo($data['user_bloodgroup']==$bloodgp)?'checked':'' ?>>
<option value="A+">A+</option
<option value="B+">B+</option>
<option value="AB+">AB+</option>
<option value="O+">O+</option>
<option value="A-">A-</option>
<option value="B-">B-</option>
<option value="AB-">AB-</option>
<option value="O-">O-</option>
</select>
</body>
</html>
You can get value by using <?php print_r($_POST); ?> on your recieving php page.
Considering your <select> is in a <form>, depending on the method (get or post), when submitting, the value will be store in $_GET or $_POST.
// Example with post
<?php
//Verifying the form has been submitted
if (isset($_POST) && isset($_POST['submit'])) {
// here is the value you want
$select_value = $_POST['bloodgp'];
}
?>
If you are looking to do something when the user choose an <option> and not on submit of a form, this will be done with JavaScript.
You can find answers here as I did myself sometime ago (read the 2 firsts answers).
Next time, please search for already answered questions, post your code, and explain more what you are trying to do and how.
Please do not bother to put your code here, which is easy to understand.
Well you want to send a blood group which is selected by the user and now want to show this in html,
the common format of select box is
<select name="bloodgp">
<option value="A+">A+</option
<option value="B+" selected >B+</option>
</select>
this selected attribute will show this on html not checked, so you can use javascript to check all the options value which on match then add this attribute or you can easily print it as first option like
<select name="bloodgp">
<option value = "<?php echo $data['user_bloodgroup'];?>" selected><?php echo $data['user_bloodgroup'];?></option>
<option value="A+">A+</option
<option value="B+">B+</option>
</select>
which will make that option double. In my case i will like to use js to filter that option.

Related Links

How to make a dynamic json list/array with database values
programming, logic using gloabal variables
Self Executable Code In PHP
Magento patch-SUPPEE-6285 not installing for V 1.7.0.2
XCLASS - Fatal error: Call to undefined method
opencart site becomes extremely slow after migrating to new server
PHP - update string with html links
Recursive dropdown menu not showing correctly on Bootstrap Codeigniter
PHP and cURL - Multiform request with file and text
How can i make my paragraph go to the next line after a certain width
PHP: Include an array inside another array that gets DB rows
Edit value to database through custom admin, Opencart 2.0
cURL systematically times out when trying to connect
Why does this function return zero? [closed]
How to import big file sql to mysql locally
google news search php - Why wont this sample code run? [closed]

Categories

HOME
google-chrome
list
clearcase
yahoo-weather-api
applescript
key
plaid
autocomplete
elisp
flurry
native-base
clish
xbap
powermock
ex
stimulsoft
django-rq
twisted
user-defined-types
l20n
gmp
xsl-fo
significance
pfobject
social-tables
neo4j.rb
software-packaging
environment
spreadsheetgear
basex
cube
docx4j
intune
snap-framework
custom-keyboard
android-canvas
text-decorations
tidal-scheduler
ejml
coverage.py
google-prediction
latexml
apache-toree
music21
ssi
rm
supertest
entropy
maven-jaxb2-plugin
line-intersection
scala-collections
gnome-terminal
perl-data-structures
researchkit
data-management
jsr363
deeplink
opencyc
espresso
vdm-sl
compositetype
com0com
console.log
camus
lifetime
hp-idol-ondemand
zend-mail
producer
full-text-indexing
screwturn
cpu-time
jmenubar
pbkdf2
bcdedit
jsplitpane
email-verification
multiple-dispatch
audiotoolbox
thejit
gamesalad
liveconnect
uploading
navigationcontroller
asio
server-variables
solandra
resharper-5.1
activestate

Resources

Encrypt Message