Passing two variables from dropdownmenu in PHP - php

I want to reload my page (PHP) on changing value from the dropdownmenu and passing the value of selected item as a variable alongwith one another variable to the page. I have tried following -
<select name="application" onChange=Refresh(this.value,$query)" \>
<option>Any Application</option>
<option>ChIP</option>
<option>Enzyme Immunoassay</option>
<option>ELISA</option>
<option>Flow Cytometry</option>
<option>FACS</option>
</select>
The Refresh function is:
function Refresh(id,gene){
location.href="getnet.php?app=" + id + "&query=" + gene;
}
And i am receiving variables as:
$query = $_POST['gene'];
$app = $_POST['application'];

you must use form submit() method in onchange event of the dropdown and hidden field for second parameter, for example:
<form name="myForm" method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select name="first" onChange="document.myForm.submit();">
<option value="1">Value 1
<option value="2">Value 2
<option value="3">Value 3
</select>
<input type="hidden" name="second" value="second parameter value"/>
</form>
On the server side you can get your variables in $_GET supperglobal array like:
$_GET['first'] - it's value from dropdown element and $_GET['second'] - second hidden param.

Try to write js function for dropdown onchange event. Below is sample code:
<script type="text/javascript">
function reload_url(val){
window.location.href = 'some_php_file.php?new_var='.val;
}
</script>
<select name="my_Sel" onchange="reload_url(this.value);">
<option value="1">1</option>
<option value="2">2</option>
</select>

What about trying a form submit onChange?
<form name="form" action="url" method="get">
<select name="application" onChange="this.form.submit();" >
<option>Any Application</option>
<option>ChIP</option>
<option>Enzyme Immunoassay</option>
<option>ELISA</option>
<option>Flow Cytometry</option>
<option>FACS</option>
</select>
<input type="hidden" name="gene" value="variable" />
</form>

Related

How do I POST noUiSlider values along with the rest of my form?

I have a noUiSlider with 2 handles, a min and max age, inside my form.
If I var_dump($_POST) the form, only the sex_select value is returned.
<form method="POST">
<select name="sex_select" id="sex-select">
<option selected="selected" disabled="disabled" value="">Sex</option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>
<div name="ageValues[]" id="age-slider">
</form>
Solved.
Created two hidden inputs
<input type="hidden" name="ageMin" value="" id="ageMin-input">
<input type="hidden" name="ageMax" value="" id="ageMax-input">
Set the values of the inputs when the slider values changes
var ageslider = document.getElementById("age-slider");
var ageMin = document.getElementById("ageMin-input");
var ageMax = document.getElementById("ageMax-input");
ageslider.noUiSlider.on('update', function(values, handle) {
ageMin.value = values[0];
ageMax.value = values[1];
});

HTML Forms: The value attribute doesn't change what's sent to php

so I'm having problems with forms sending data to my php script.
My html is:
<form method="get" action="form.php">
<select name="course">
<option value"COMM1">COMM1111</option>
<option value"COMM2">COMM2222</option>
<option value"COMM3">COMM3333</option>
<option value"COMM4">COMM4444</option>
</select>
</form>
What's sent to form.php when I do
$_GET['course']
is the inner text of the chosen option.
So choosing COMM1111 gives me COMM1111 instead of COMM1
In your option tag you forgot your equal sign for value
<option value = "COMM1">COMM1111</option>
You are missing the = sign in your HTML for the value of the options.
Consider the following code which produces the values you are looking for ::
HTML:
<form method="get">
<select name="course">
<option value="COMM1">COMM1111</option>
<option value="COMM2">COMM2222</option>
<option value="COMM3">COMM3333</option>
<option value="COMM4">COMM4444</option>
</select>
<input type='submit'>
</form>
PHP:
<?php
if(!empty($_GET)){
print_r($_GET);
}
?>

Passing Drop down Select Value to URL

<select id="langu" name="langu">
<option value="English">English</option>
<option value="Chinese">中国的</option>
<option value="Korean">한국의</option>
<option value="Vietnamese">Việt</option>
</select>
The above is part of a .PHP based, based on the selection a user makes, I'd like to pass the value of the select as part of the URL for the form action:
<form name="frmLang"
action="index2.php?r=<?php echo $rguid;?>&l=[THE DROPDOWN OPTION HERE];?>"
method="post">
First off is this possible? If so, how does one pass that variable into the URL without having to go to another page? Javascript? (Cannot use AJAX).
Thanks,
H.
Change method="post" to method="get" and include $rguid as a hidden input:
<form name="frmLang" action="index2.php" method="get">
<input type="hidden" name="r" value="<?php echo $rguid; ?>">
<select id="langu" name="l">
.
.
.

Get selected value ajax

First Select
<Select id="drop1" onchange="drop1(this.value)">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
<div id = "txtHint1"></div>
Once a value has been selected, the value will be sent to ajax. And corresponding dropdown will be generated on another page and show in div txthint1.
Second Select
<Select id="drop2" onchange="drop2(this.value)">
<option value ='111'>111</option
<option value ='222'>222</option
<option value ='333'>333</option
</select>
<div id = "txtHint2"></div>
As the generated dropdown is another php page, how can I get what the value the user has selected to show on my current page (div txthint2)?
I will be working in php.
$value = $_GET['a'];
There are no submitted button.
Send out the second request on a successful response:
function one() {
$.ajax({
...
success: function() {
two(TheValueFromOne);
}
});
}
function two() {
$.ajax({
...
});
}
What is happening is that once the request has been made successfully, then it is automatically starting the next request right after.
However, if you are jsut passing values around form one page to another you really do not need AJAX.
FOR EXAMPLE:
test1.php:
<form action="test2.php" method="get">
Book Title <br />
<input type="text" name="booktitle" /><br />
<input type="submit" name="submit" value=" - Update Database - " />
</form>
test2.php
<body>
<? echo $_GET["booktitle"]; ?>
</body>
IN YOUR CASE:
test1.php:
<Select id="drop1" name="test1">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
test2.php
<Select id="drop1">
<option selected = "<? echo $_POST['test1']; ?>"></option>
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
#QUESTION:
<div id = "txtHint2"><? echo $_POST['test1']; ?></div>
#POSTING WITH FORM:
<form method="post" action="test2.php" >
<Select id="drop1" name="test1" onChange="this.parentNode.submit()">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
</form>

dropdown return value in html and php

I have dropdown list (menu) and a button created with this code:
<form name="period" action="all.php" method="POST">
<div align="center">
<select name=period_dropdown>
<option value="nill"></option>
<option value="48">48</option>
<option value="72">72</option>
<option value="96">96</option>
<option value="120">120</option>
</select>
<input type="submit" value= "OK" >
</div></form>
When option of dropdown is selected, must be on button instead of OK and when button is pressed to be assigned to variable $period1. So, when I select 72, button must have 72 instead of OK and when I click button, variable $period1 to get value 72 (integer). Please, no javascript. Just html and php.
Thanks
You have to use javascript for what you are trying to do. If you want the button to change on the fly without submitting the form, you have to do client-side scripting (javascript).
Either:
Change the value of button after the dropdown is selected and form is submitted
Use two lines of javascript to change the value of the button when the select box is changed
In all.php:
if (isset($_POST['period_dropdown'])) {
$period1 = $_POST['period_dropdown'];
//do something with $period1
}
?>
<form name="period" action="all.php" method="POST">
<div align="center">
<select id="period_dropdown" name="period_dropdown" onchange="updateButton()">
<option value="nill"></option>
<option value="48">48</option>
<option value="72">72</option>
<option value="96">96</option>
<option value="120">120</option>
</select>
<input id="period_button" type="submit" value= "OK" >
</div></form>
<script type="text/javascript">
function updateButton() {
document.getElementById("period_button").value = document.getElementById("period_dropdown").value;
}
</script>

Categories