<!DOCTYPE html>
<html lang="ro">
<head>
<title>MODIFICA</title>
</head>
<body>
<?php
$select1 = isset($_POST['select1']) ? $_POST['select1'] : '';
if($select1 == 'da'){echo 'ok';}
else { echo '!ok'; }
?>
<form method="POST">
<table border="1">
<thead>
<tr>
<th>Nume</th>
<th>Prenume</th>
<th>Adresa</th>
<th>Partid</th>
<th>Consiliul Local</th>
<th>Primar</th>
<th>Consiliul Judetean</th>
<th>Presedinte Consiliul Judetean</th>
<th>Senat</th>
<th>Deputat</th>
<th>Comisia Europarlamentara</th>
<th>Presedinte</th>
<th>Submit</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $db->prepare('SELECT nume,prenume,adresa,partid,consiliul_local FROM candidati');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_OBJ)):?>
<tr>
<td><?php echo $row->nume;?></td>
<td><?php echo $row->prenume;?></td>
<td><?php echo $row->adresa;?></td>
<td><?php echo $row->partid;?></td>
<td>
<select name="select1">
<option value=""></option>
<option value="<?php echo $row->consiliul_local;?>">
<?php echo $row->consiliul_local;?>
</option>
</select>
</td>
<td>
<select name="select2">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select3">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select4">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select5">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select6">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select7">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select8">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<button type="submit" name="btn">SUBMIT</button>
</td>
</tr>
<?php endwhile;?>
</tbody>
</table>
</form>
</body>
</html
I just verify if the $select1 variable is set, and if it's the case, then if the value from "option" (line 44), is 'da', then display it.
The problem that I have is that value is not displayed accordingly. Anyone knows why, and what should I change in order to work?
Or, in simple words, for starting coding the page I need, firstly I just filled-in that "option" tag with the value from db (and yes, the value 'da' is presented in 'consiliul_local' field from db), and then I made a simple echo, above the "form", and if the value of the "select" is 'da', then it should display the message 'ok'. But it always displays the message placed on the else branch. I must specify that I must do the whole logic only with php, and not js or anything else.
Here is how my page looks like, and notice that selected 'da' in the dropdown, which is there because of the MySQL fetch (line 35 in pastebin).
http://www.2shared.com/photo/eXzJ7Glo/1_online.html
This is the page source, which says the value stored in db, is correctly inserted into that value attribute of the tag.
http://www.2shared.com/uploadComplete.jsp?sId=CACRC8H4n6GrF0jJ
So I select 'da' from that dropdown, then I press the button, and I expect the 'ok' message to be displayed. Any fix? Thanks so much!
Related
I have three dropdown boxes. Namely DS, QA, Mod. First step is DS will select a value (YES/NO) & upon submitting, QA will be reviewing the input of DS. I have to get the values of DS Dropdown and display it in the same dropdown box of DS(disabled) when QA is about to check the input.Same goes with Mod.Take note that these dropdown boxes exists in checklist.php file.
<table width="100%" border="1">
<tbody>
<tr>
<td align="left" rowspan="2"><b>Check Items</b></th>
<td><b>DS</b></td>
<td><b>QA</b></td>
<td><b>Mod?</b></td>
</tr>
<tr>
<td align="center" rowspan="2"><select id="valueDS1">
<option value="YD1">YES</option>
<option value ="NAD1">N/A</option>
</select>
</td>
<td align="center" rowspan="2"><select id="valueQA1">
<option value="YQ2">YES</option>
<option value ="NAQ2">N/A</option>
</select>
</td>
<td align="center" rowspan="2"><select id="valueMod1">
<option value="YM1">YES</option>
<option value ="NM1">NO</option>
</select>
</td>
</tr>
<tr>
<td> All extra instructions and corrections applied.</td>
<tr>
<td>
<p> If comments exist, ask DE if they need to be deleted or retained (but hidden)</p>
</td>
<td align="center"><select id="valueDS2">
<option value="Y">YES</option>
<option value ="NA">N/A</option>
</select>
</td>
<td align="center"><select id="valueQA2">
<option value="Y">YES</option>
<option value ="NA">N/A</option>
</select>
</td>
<td align="center"><select id="valueMod2">
<option value="Y">YES</option>
<option value ="NA">NO</option>
</select>
</td>
</tr>
</table>
Inside the PHP code, assign a variable to the dropdown.
$DS= $_POST['DS']
Now, in the HTML of the dropdown do something like following
<select>
<option <?php if(isset($DS) && $DS=="yes" ){ echo "selected"; } ?> value="yes" disabled>Yes</option>
</select>
I am having multiple submit buttons.
and in a row i have 2 select options and a submit button.
how to generate unique rowid for each submit button
want to make each submit and select options unique and post it to the next page
You can use as follows with row id if you have...
<input type="submit" id="button_<?php echo $row['id'];?>" name="button_submit"/>
And if not then you can use it through loop... and set id as "button_"/>
<tr>
<th>S.NO</th>
<th>Proposed Action</th>
<th>Submitted/Return To</th>
<th>Click</th>
</tr>
<?php
$sno=1;
print" <tbody>
<tr>
<td> <select name='select2' class='selectpicker' id='select2'>
<option value='-2'>a</option>
<option value='99'>p</option>
<option value='88'>c</option>
<option value='77'>d</option>
<option value='66'>v</option> </select> </td>
<td> <select name='select' class='selectpicker' id='select' >
<option value='0'><------select------></option>
<option value='4'>apple</option>
<option value='5'>mango</option>
<option value='6'>berry</option>
</select> </td>";?>
<?php print"
<td><input type='submit' name='forward$sno' value='forward'></td>
</tr>
</tbody>";
$sno++;
}?>
</table>
</form>
I am trying to get the value from a selectbox. The form is placed multiple times on my page with a php loop (that's why I use classes instead of id's).
<html>
<body>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="media" class="media">
<?php foreach($images as $image){if(substr($image,0,1) != '.'){ ?>
<option style="background-image:url(<?=$d_images.$image?>)" value="<?=$image?>" <?php if($r_media== $image) echo 'selected="selected"'; ?>><?=$image?></option>
<?php }} ?>
</select>
</td>
</tr>
</form>
</table>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="media" class="media">
<?php foreach($images as $image){if(substr($image,0,1) != '.'){ ?>
<option style="background-image:url(<?=$d_images.$image?>)" value="<?=$image?>" <?php if($r_media== $image) echo 'selected="selected"'; ?>><?=$image?></option>
<?php }} ?>
</select>
</td>
</tr>
</form>
</table>
</body>
</html>
With jQuery I am trying to get the selected option.
$(function(){
$('.lesmaker').each(function() {
console.log($(this).find('.type').val());
});
});
The code above is not working. How do I need to do this?
$(function() {
$('.lesmaker').each(function() {
console.log($(this).find('table tr td').find('.type').val());
});
});
You need to change your HTML to following:
<form class="lesmaker">
<table>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
</table>
</form>
form needs to be either outside of table or inside of td :)
$(function() {
$('.type').each(function() {
console.log($('option:selected', this).val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie" selected="selected">Klassikaal</option>
<option value="meerkeuze" >Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info" selected="selected">Informatie</option>
<option value="discussie" >Klassikaal</option>
<option value="meerkeuze" >Meerkeuze</option>
</select>
</td>
</tr>
</form>
</table>
Just use the class of select and use $('option:selected', this).val()
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