<form action="index.php" method="post">
<select name="imageslist" onchange='this.form.submit()' >
<option value="0">Select One</option>
<option value="1">Image 01</option>
<option value="2">Image 02</option>
<option value="3">Image 03</option>
<option value="4">Image 04</option>
<option value="5">Image 05</option>
<option value="6">Image 06</option>
<option value="7">Image 07</option>
<option value="8">Image 08</option>
<option value="9">Image 09</option>
<option value="10">Image 10</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
In my index.php I have the following
var image1 = '<img id="img_<?php echo $_POST['imageslist']; ?>" src="images/<?php echo $_POST['imageslist']; ?>.png" />';
var image2 = '<img id="img_2" src="images/2.png" />';
var image3 = '<img id="img_3" src="images/3.png" />';
How can I get the next 2 values of the selected item?
Sorry i didn't understand your question completely
hope this helps you
<script type="text/javascript">
function test(a)
{
var r=document.forms['fm'].imageslist[(parseInt(a.value)+1)];
document.getElementById('second').value=r.value;
var r2=document.forms['fm'].imageslist[(parseInt(a.value)+2)];
document.getElementById('third').value=r2.value;
}
</script>
<form action="index.php" method="post" name='fm'>
<select name="myList" onchange='test(this)' >
<option value="0">Select One</option>
<option value="1">Image 01</option>
<option value="2">Image 02</option>
<option value="3">Image 03</option>
<option value="4">Image 04</option>
<option value="5">Image 05</option>
<option value="6">Image 06</option>
<option value="7">Image 07</option>
<option value="8">Image 08</option>
<option value="9">Image 09</option>
<option value="10">Image 10</option>
</select>
<input type="submit" value="Submit">
<input type="hidden" name="second" id="second">
<input type="hidden" name="third" id="third">
</form>
in index.php
print_r($_POST);// Array ( [myList] => 4 [second] => 5 [third] => 6 )
Related
I am pretty new to PHP and have looked for a solution for what I'd have thought would be a common question but I can't find the answer. Any help would be greatly appreciated.
So I have a form with a selector and various options:
<form class="form-horizontal" id="main-home-form" action="trip_search_process.php" method="post">
<div class="form-group">
<label>Select location:</label>
<select class="form-control" id="location_selector" name="location">
<option value="default">I Don't Mind...</option>
<option value="africa">Africa</option>
<option value="asia">Asia</option>
<option value="aus_nz">Australia & New Zealand</option>
<option value="europe">Europe</option>
<option value="north_america">North America</option>
<option value="south_america">South America</option>
</select>
When this form is submitted, I have this PHP code which extracts the location selected:
$location_passed = $_POST["location"];
However, what is passed is the contents of the 'option'. What I would like is the value. I.e. for this 'option':
<option value="aus_nz">Australia & New Zealand</option>
I currently get 'Austraia & New Zealand', whereas I want aus_nz
Is this possible? Or am I going about this the wrong way?
<?php
if(isset($_POST['re'])){
if($_POST['location'] == 'default'){
// error
echo '<p>make a selection</p>';
}else{
$val = $_POST['location'];
echo '<p> selected value; '.$val.'</p>';
}
}
?>
<form class="form-horizontal" id="main-home-form" action="" method="post">
<div class="form-group">
<label>Select location:</label>
<select class="form-control" id="location_selector" name="location">
<option value="default">I Dont Mind...</option>
<option value="africa">Africa</option>
<option value="asia">Asia</option>
<option value="aus_nz">Australia & New Zealand</option>
<option value="europe">Europe</option>
<option value="north_america">North America</option>
<option value="south_america">South America</option>
</select><br>
<input type="submit" name="re" id="re" value="value.">
</div>
</form>
the above code will give the value of the selected option.
Put the php code to your action page trip_search_process.php
<?php
if(isset($_POST['submit'])){
echo $value = $_POST["make"];
echo $text = $_POST["make_text"];
}
?>
<form method=post>
<select name='make' onchange="setTextField(this)">
<option value = '' > Please Select Value </option>
<option value = '5'> Text 5 </option>
<option value = '7'> Text 7 </option>
<option value = '9'> Text 9 </option>
</select>
<br/>
<input type=submit name=submit>
<input id="make_text" type = "hidden" name = "make_text" />
<script type="text/javascript">
function setTextField(ddl) {
document.getElementById('make_text').value = ddl.options[ddl.selectedIndex].text;
}
</script>
</form>
Before anyone yells Repost, there aren't many cases like mine that I've seen.I have a contact form that has the possibility to have a main Select option, a sub-Select option and then a sub-Select option of that one. Overall, There are 27 options to choose from and I think I could make the php give me all 27 of those and then do a "yes they selected this one but not that one" type of report, but I digress.How do I have the php script for my contact form send only what is selected from a possible three-tiered select menu? EDIT: I'm totally willing to use something other than PHP to help facilitate this, I just need help with the PHP script as well.Edit: To be clear, I'm try to create and populate a php script, not valdiate the form/check that all required sections are filled out.Code
<form action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option>Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option>Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option>Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option>Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
</form>
I assume that you do have jquery to display the relevant select boxes upon selection of devices etc... I have made a few changes in your html form, like adding id="form" in your form tag. Also added value="" for options like "Please select Service".. Here is the code. Hope this helps.. Refer to this as well..
Jquery form submit to check empty fields
<form id="form" action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option value="">Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option value="">Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option value="">Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option value="">Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('select').change(function(){
var boxid = $(this).children('option:selected').attr('data-target');
alert(boxid);
if(boxid == "devices") {
var divId = "service-" + boxid;
}
document.getElementById(divId).style.display = "block";
});
$("form").submit(function(){
// $(':input[value=""]').attr('disabled', true);
$("input[type='text'],select,input[type='password'],textarea",this).each(function() {
if($(this).val().trim() == "") {
$(this).attr('disabled', true);
}
})
});
});
</script>
I've been trying to post the value of two selected dropdown menu's using the SESSIONS method, however there seems to be an issue because when submitted the second page displays the PHP code only. Here are the relevant snippets of code:
shop.php
<form action="processing.php" method="post"> <div class="item">
<span class="caption">Essential Gray Suit<br />£459</span>
<select name="size1" class="size" id="size1" onchange="showDiv(this)">
<optgroup label="Size">
<option value="0">SELECT SIZE</option>
<option value="1">XS</option>
<option value="2">S</option>
<option value="3">M</option>
<option value="4">L</option>
<option value="5">XL</option>
</select>
<div id="quantity1" style="display: none;">
<select name="quantity1" class="size" onchange="showCart(this)">
<optgroup label="Quantity">
<option value="0">SELECT QUANTITY</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<input type="submit" value="Submit" name="submit" id="submit">
</form>
processing.php
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['size1'] = $_POST['size1'];
}
echo $_SESSION['size1'];
?>
I have an php form which contains 7 dropdown lists. When selecting a value from one of this I want the others 6 to return to their default values if they were previously opened. I think it should be used a javascript for this but I don't now to write such a script. I guess each of this dropdown list must have an ID and when I select an option from each one of the 7 the javascript should recognise the id and sets the other to default. I tried using a javascript with document.getElementsByName('id') but it doesn't work.
<form id="form1" name="form1" method="post" action="">
<select name="select" size="1" id="1">
<option value="0" selected="selected">please select</option>
<option value="1">blue</option>
<option value="2">green</option>
<option value="3">red</option>
</select>
<br />
<select name="select2" size="1" id="2">
<option value="0" selected="selected">please select</option>
<option value="1">intel</option>
<option value="2">amd</option>
</select>
<br />
<select name="select3" size="1" id="3">
<option value="0" selected="selected">please select</option>
<option value="1">fish</option>
<option value="2">car</option>
<option value="3">table</option>
</select>
<br />
<select name="select4" size="1" id="4">
<option value="0" selected="selected">please select</option>
<option value="1">lcd</option>
<option value="2">led</option>
</select>
</form>
This is my form.
Let's sey for example I select a value from the second dropdown list "intel". After this i select from the 3rd dropdown list a value "table". What i need to do is when selecting from the 3rd dropdownlist the second one returns to "please select".
The ideea is that using a javascript i do not want those who use the form to select more than one dropdown list at a time.
They should be able to see the values from each one opening the dropdown list but if they open another one the previously must return to the selected="selected" option which is "please select".
Thanks.
Here is a idea to start. Consider 2 dropdown like this.
<select id="Numeric">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="Alphabets">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
Based on the value of 1st dropdown i am selecting the second dropdown
var val = document.getElementById("Numeric").value;
var obj = document.getElementById("Alphabets");
if(val == "1") obj.value = "A"
else if(val == "2") obj.value = "B"
else if(val == "3") obj.value = "C"
Switch is more better
switch(val)
{
case("1"):
obj.value = "A";
break;
case("2"):
obj.value = "B";
break;
case("3"):
obj.value = "C";
break;
}
This is very basic starup idea. You need to implement good logics for your needed functionality
Updated Answer after Comments
<html>
<head>
<script type="text/javascript">
function handleSelect(thisObj){
var list = document.getElementsByTagName("SELECT")
for(var i=0; i< list.length; i++)
{
if(list[i] ==thisObj) continue;
list[i].value = "0";
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<select name="select" size="1" id="1" onchange="handleSelect(this)">
<option value="0" selected="selected">please select</option>
<option value="1">blue</option>
<option value="2">green</option>
<option value="3">red</option>
</select>
<br />
<select name="select2" size="1" id="2" onchange="handleSelect(this)">
<option value="0" selected="selected">please select</option>
<option value="1">intel</option>
<option value="2">amd</option>
</select>
<br />
<select name="select3" size="1" id="3" onchange="handleSelect(this)">
<option value="0" selected="selected">please select</option>
<option value="1">fish</option>
<option value="2">car</option>
<option value="3">table</option>
</select>
<br />
<select name="select4" size="1" id="4" onchange="handleSelect(this)">
<option value="0" selected="selected">please select</option>
<option value="1">lcd</option>
<option value="2">led</option>
</select>
</form>
</body>
</html>
i'm trying to use comboboxes for quantity in Virtuemart instead of quantity text and update button.
When i have only one article in the cart it works perfectly, but when i have more than one, it's not working.
Here's the form code
<form action="<?php echo JRoute::_ ('index.php'); ?>" method="post" class="inline" name="frm">
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="text" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>.2" class="inputbox" size="3" maxlength="4" name="quantity" value="<?php echo $prow->quantity ?>" style="display:none;"/>
<select name="cantidad" id="cantidad" onchange="getval(this);" value="<?php echo $prow->quantity ?>" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>"> <script type="text/javascript">
function getval(sel) {
document.frm.quantity.value = (sel.value);
document.getElementById('actualizar').click();
}
</script>
<option value="<?php echo $prow->quantity ?>"><?php echo $prow->quantity ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select>
<input type="hidden" name="view" value="cart"/>
<input type="hidden" name="task" value="update"/>
<input type="hidden" name="cart_virtuemart_product_id" value="<?php echo $prow->cart_item_id ?>"/>
<input type="submit" class="vmicon vm2-add_quantity_cart" id="actualizar" name="update" title="<?php echo JText::_ ('COM_VIRTUEMART_CART_UPDATE') ?>" align="middle" value=" " style="display:none;"/>
</form>
Thank you