I have a dropdown where user select some values and moves to other dropdownlist in sorted order by javascript. How can I get the chosen value in second dropdownlist in next page to a PHP variable ?
<form name="Example" action="next.php" method="post">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<select name="Features" size="9" MULTIPLE>
<option value="2">Row 2</option>
<option value="4">Row 4</option>
<option value="5">Row 5</option>
<option value="6">Row 6</option>
<option value="7">Row 7</option>
<option value="8">Row 8</option>
<option value="9">Row 9</option>
</select>
</td>
<td align="center" valign="middle">
<input type="Button" value=">>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)">
<br>
<input type="Button" value="<<" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)"><br>
<input type="Button" value=">>>>" style="width:100px" onClick="selectAll(document.Example.Features);SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
<input type="Button" value="<<<<" style="width:100px" onClick="selectAll(document.Example.FeatureCodes);SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
</td>
<td>
<select name="FeatureCodes[]" id="FeatureCodes" size="9" MULTIPLE>
<option value="1">Row 1</option>
<option value="3">Row 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="submit" id="submit" name="submit"></td>
</tr>
</table>
Thanks in advance!!
The value of the selected element in your second form field should be in:
$_POST['FeatureCodes'][0];
If you only have one FeatureCodes form on the page then you can remove the [] from your HTML and access it using $_POST['FeatureCodes'];
Related
Here is a small section of my form. It is set up that a user can add information about one munro, or multiple. Hence the use of arrays for input boxes, check boxes and select option boxes.
<fieldset class="row1">
<H2>Munro Details</H2>
<table id="munroTable" class="form" border="0">
<tbody>
<tr>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Name</label>
<input class = "textbox" type="text" maxlength = "30" required="required" name="name[]">
</td>
<td>
<label>Height (metres)</label>
<input class = "textbox" type="number" maxlength = "5" required="required" name="height[]">
</td>
<td>
<label>Classification</label>
<select name = "classification[]">
<optgroup label="Scottish Hills">
<option value="Munro">Munro</option>
<option value="Corbett">Corbett</option>
<option value="Graham">Graham</option>
<option value="Donald">Donald</option>
</optgroup>
<optgroup label="Non Scottish Hills">
<option value="Furth">Furth</option>
<option value="Hewitt">Hewitt</option>
<option value="Wainwright">Wainwright</option>
<option value="Brikett">Brikett</option>
</optgroup>
<optgroup label="UK wide">
<option value="Marilyn">Marilyn</option>
</optgroup>
</select>
</td>
<td>
<label>Topped?</label>
<input type="checkbox" value = "Yes" name="topped[]" checked="checked">
</td>
</tr>
</tbody>
</table>
<p>
<input class = "myButton" type="button" value="Add Munro" onClick="addRow('munroTable')" />
<input class = "myButton" type="button" value="Remove Munro" onClick="deleteRow('munroTable')" />
</p>
</fieldset>
The issue I'm having is with the select option for "classification".
When I use echo "<br>All data".print_r($_POST); so see what data is being sent sucessfully, the classification doesn't show up.
I'm assuming it is something very simple, but I just can't find it.
Thanks for taking the time to look.
This may be a duplicate question,
But still, I did not find the answer.
My requirement is :
How to get the table rows which are CHECKED.
Here is my issue's screenshot. enter image description here
My checkbox name is 'check[]'
and the name of the select box is 'class[]',
and the form is posted to process.php.
How to get the value of 'class[]' where the checked boxes are checked so that I can then process with PHP-MYSQL?
My code is here:
<div class="col-md-5">
<form action="process.php" method="post">
<table class="table" id="table">
<tr><th>Opt</th><th>Name</th><th>Next Class</th></tr>
<? $q = $sdb->where('ac_CurClass',4)->get('tbl_accounts');
foreach ($q as $r){ ?>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="<?=$r['ac_Id'];?>"></td>
<td><?=ac_details($r['ac_Id'])->ac_Name;?></td>
<td>
<select class="form-control small" name="class[]">
<? $c = $sdb->where('c_Id',ac_details($r['ac_Id'])->ac_CurClass,">")->get("tbl_classes");
foreach($c as $d) {?>
<option value="<?=$d['c_Id'];?>"><?=$d['c_Name'];?></option>
<? } ?></select>
</td>
</tr>
<? } ?>
</table>
<button type="submit" class="btn btn-danger">Update</button>
</form>
</div>
Hope this code is help full for you
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="col-md-5">
<form action="#" method="post">
<table class="table" id="table">
<thead><tr><th>Opt</th><th>Name</th><th>Next Class</th></tr></thead>
<tbody id="cont">
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="1"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="2"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="3"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" id="submit">Update</button>
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$("#cont input:checkbox:checked").map(function(){
alert('Checkbox value - '+$(this).val()+' / Select Box value - '+$(this).parent().next().next('td').find('select').val());
//alert('Select Box value - '+$(this).parent().next().next('td').find('select').val());
});
});
});
</script>
After that you can pass a Ajax so that only checked rows post.
Try as follows
Post as form
<form action="process.php" method="post">
In process.php file
if($check[0]===true){
$nextclass1 = $_POST['list_box'];
}
if($check[1]===true){
$nextclass2= $_POST['list_box'];
}
The following is my HTML. I want to pass the name of the dropdownlist(d1and d2) to another survey.php page when the button is clicked.
<!DOCTYPE html>
<head>
<title>Survey</title>
</head>
<body>
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="g">Good</option>
<option value="s">bad</option>
<option value="u">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
Rewrite:
<form id="form1" action="survey.php" method="POST">
<table border=1>
<tr>
<td height=" 30" width="200">
Condition of the item received:
<select name="d1">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
<td height=" 30" width="200">
Price of the Item:
<select name="d2">
<option>Select One</option>
<option value="Good">Good</option>
<option value="bad">bad</option>
<option value="Worst">Worst</option>
</select>
</td>
</tr>
<tr>
<td align="center" >
<input type="button" name="submit1" value="Submit" />
</td>
</tr>
</table>
</form>
Firstly, instead of: <input type="button" name="submit1" value="Submit" />
Use: <input type="submit" name="submit1" value="Submit" />
<input type="submit"> is what is used to actually send the form.
Secondly, in the body of survey.php:
<?php
echo "You rated ".$_POST['d1']." for condition."
echo "You rated ".$_POST['d2']." for price."
?>
In short:
The $_POST variable in PHP is automatically set to a dictionary containing all the POST parameters.
Trying to pass the value from Drop down list through but couldnt get it.
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><a href= manageProduct.php?size=$_GET[size]>Insert</a></td>
</tr>
Give this a try: (just an example).
<form action="<?php $_SERVER['PHP_SELF']?>" method="GET">
<table>
<tr>
<td nowrap>Size:
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td><p align="right"></p></td>
<td><input type="submit" value="Insert" />
</td>
</tr>
</table>
</form>
<?php
$size = $_GET['size'];
if($_GET['size']=="N")
{
echo "you chose NOTHING, make another choice.";
}
else {
echo "Your choice of size is: $size";
}
?>
Html
<form action="manageProduct.php" method="POST">
<table>
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Insert" /></td>
</tr>
</table>
</form>
PHP
$size = $_POST['size'];
You need a form using the GET action then you can get your variable.
Assuming this page is the manageProduct.php:
<!--GET your data from the submitted form OR do something depending on what size returns in the url-->
<?php
if($_GET['size']=="SIZE"){ echo whatever or do whatever}
?>
<td>Whatever you're trying to do</td>
<form id="form" method="get" action="manageProduct.php">
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Insert" /></td>
<br />
</form>
</tr>
I have a form with three different dropdown menus, it looks like this:
<FORM METHOD="LINK" ACTION="/search.php" method="get">
<select style="width:55px;" name="filter_name">
<option> </option>
<option>R13</option>
<option>R14</option>
<option>R15</option>
<option>R16</option>
<option>R17</option>
</select></td></tr>
<tr><td width="40%">Plotis:</td><td colspan="2"><select style="width:55px;" name="">
<option> </option>
<option>165</option>
<option>175</option>
<option>185</option>
<option>195</option>
<option>205</option>
<option>215</option>
<option>225</option>
</select></td></tr>
<tr><td width="40%">Aukštis:</td><td colspan="2"><select style="width:55px;" name="">
<option> </option>
<option>75</option>
<option>70</option>
<option>65</option>
<option>60</option>
<option>55</option>
<option>50</option>
<option>45</option>
</select></td></tr>
<tr><td colspan="2" align="center">
<INPUT style="width:80px; height:25px; font-size:14px; font-weight:600; cursor:pointer;" TYPE="Submit" VALUE="Ieškoti">
</FORM>
Basically, I need to send all 3 Options into next page but joined into one variable..
For example: If I chose
<option>165</option>+<option>70</option>+<option>R13</option>
it should be sent to index.php like this: filter_name=165/70/R13
and also, how to send all this not to index.php only, but to
index.php?route=product/search&FILTER_NAME
Changing ACTION="/index.php" to ACTION="/index.php?route=product/search" was not working.
Any help would be really appreciated.
You could try something like this. But, you have several errors in your HTML that you should check. You have a nested table within your form.
<?php
if (!isset($_POST['send'])) {
?>
<form method="post" action="">
<select style="width:55px;" name="select_one">
<option> </option>
<option value="R13">R13</option>
<option value="R14">R14</option>
<option value="R15">R15</option>
<option value="R16">R16</option>
<option value="R17">R17</option>
</select>
<select style="width:55px;" name="select_two">
<option></option>
<option value="165">165</option>
<option value="175">175</option>
<option value="185">185</option>
<option value="195">195</option>
<option value="205">205</option>
<option value="215">215</option>
<option value="225">225</option>
</select>
<select style="width:55px;" name="select_three">
<option></option>
<option value="75">75</option>
<option value="70">70</option>
<option value="65">65</option>
<option value="60">60</option>
<option value="55">55</option>
<option value="50">50</option>
<option value="45">45</option>
</select>
<input style="width:80px; height:25px; font-size:14px; font-weight:600; cursor:pointer;" type="submit" value="send" value="Ieškoti" />
</form>
<?php
}
else {
header('Location: index.php?route=product/search&filter_name='.$_POST['select_two'].'/'.$_POST['select_three'].'/'.$_POST['select_one']);
}
?>
Join the 3 filter options in php into a variable.
$options = $_POST['f1'] . '/' . $_POST['f2'] . '/' . $_POST['f3'];
It will be less confusing IMO.
The problem can be in the invalid markup. You are using table layout, and form is split between cells. That is not valid, so may be browser renders your layout in an unexpected way.
You can expect this:
<table>
<tr>
<td>
<form>
<input>
</td>
<td>
<input>
</form>
</td>
</tr>
<table>
But browser can render your markup as this (2 forms):
<table>
<tr>
<td>
<form>
<input>
</form>
</td>
<td>
<form>
<input>
</form>
</td>
</tr>
<table>
So when you submit your form not all data are sent, cause only first form is submitted