I am trying to post the name="pricetag" and name="size" which is in the item and price... I know this is not working because I have use echo but nothing is coming out but if I echo the pid of the product I shows. The codes below
<form id="add2cart" name="cart" method="Post" action="<?php fetchdir($bpages); ?>cart.php">
<table>
<tr>
<td width="160">Price:</td>
<td name="pricetag" id="pricetag">£25.00</td>
</tr>
<tr>
<td width="160">Item:</td>
<td name="size" id="item">12 inch</td>
</tr>
<tr>
<td width="160">Length*:</td>
<td>
<select name="length" onChange="addCharge(this, this.selectedIndex);" id="priceDropDown" class="small">
<option value="£25.00">12 inch</option>
<option value="£30.00">14 inch (+£30.00)</option>
<option value="£35.00">16 inch (+£35.00)</option>
<option value="£40.00">18 inch (+£40.00)</option>
<option value="£45.00">20 inch (+£45.00)</option>
<option value="£55.00">22 inch (+£55.00)</option>
<option value="£60.00">24 inch (+£60.00)</option>
<option value="£70.00">26 inch (+£70.00)</option>
<option value="£80.00">28 inch (+£80.00)</option>
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="Qty" id="Qty" value="1" style="width: 20px; text-align: right" /></td>
</tr>
</table>
<div class="cleaner h20"></div>
<input type="hidden" name="pid" id="id" value="<?php echo $id; ?>" />
<input type="Submit" class="button" name="button" id="button" value="Add to shopping cart"/>
</form>
click here for live code http://jsfiddle.net/J4rXX/5/ by Ghillied
It doesn't POST because forms don't submit contents from TD elements. Only from INPUTs, SELECTs and TEXTAREAs.
More information on HTML FORMs here. If you want to avoid displaying the same data twice, you should try INPUT type=hidden.
<table>
<tr>
<td>Pricetag</td><td>PRICE_HERE</td>
</tr>
</table>
<form>
<input type="hidden" name="pricetag" value="PRICE_HERE" />
...
</form>
This should do nothing to hurt your existing JS scripts.
The only information that is posted to the server from a HTML form are elements such as INPUT, SELECT, and TEXTAREA.
If you want to post additional data, but make it un-editable to the user, you need to ideally put the data into INPUT elements which have the attributes type="hidden". This will post the data from the field but make them hidden to the user posting the form.
Adding the elements anywhere in the form will work. I've positioned them at the bottom of the form element, with the already existing hidden field, in this snippet.
I've also removed the name attributes from the TD elements in the snippet, to conform with web standards.
<form id="add2cart" name="cart" method="Post" action="<?php fetchdir($bpages); ?>cart.php">
<table>
<tr>
<td width="160">Price:</td>
<td id="pricetag">£25.00</td>
</tr>
<tr>
<td width="160">Item:</td>
<td id="item">12 inch</td>
</tr>
<tr>
<td width="160">Length*:</td>
<td>
<select name="length" onChange="addCharge(this,this.selectedIndex);" id="priceDropDown" class="small">
<option value="£25.00">12 inch</option>
<option value="£30.00">14 inch (+£30.00)</option>
<option value="£35.00">16 inch (+£35.00)</option>
<option value="£40.00">18 inch (+£40.00)</option>
<option value="£45.00">20 inch (+£45.00)</option>
<option value="£55.00">22 inch (+£55.00)</option>
<option value="£60.00">24 inch (+£60.00)</option>
<option value="£70.00">26 inch (+£70.00)</option>
<option value="£80.00">28 inch (+£80.00)</option>
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="Qty" id="Qty" value="1" style="width: 20px; text-align: right" /></td>
</tr>
</table>
<div class="cleaner h20"></div>
<input type="hidden" name="pricetag" value="£25.00" id="hiddenpricetag" />
<input type="hidden" name="size" value="12 inch" id="hiddensize" />
<input type="hidden" name="pid" id="id" value="<?php echo $id; ?>" />
<input type="Submit" class="button" name="button" id="button" value="Add to shopping cart"/>
</form>
EDIT:
Just noticed that the form uses javascript, upon the change of the SELECT data, to change the TD elements HTML data.
To make sure that the form posted the correct data that is in the TD elements, you would need to add ID tags to the hidden input fields so that you can program the javascript to update these as well as the TD elements.
I've added the IDs hiddenpricetag and hiddensize to the two hidden fields.
Your javascript function should be somewhat like this:
function addCharge(select, elemIndex)
{
var item = select.getElementsByTagName('option')[elemIndex];
var price = document.getElementById('pricetag');
var sizeDOM = document.getElementById('item');
var hiddenpricetag = document.getElementById('hiddenpricetag');
var hiddensize = document.getElementById('hiddensize');
var finalPrice = "";
/* Getting the price and showing it up */
finalPrice = parseFloat(item.text.substring(11, item.text.length-1));
/* We set a default £25.00 value */
if(isNaN(finalPrice)) finalPrice = "25";
/* we add decimal */
price.innerHTML="£"+finalPrice+".00";
/* Getting the size and showing it up */
var size = item.text.substring(0,7);
sizeDOM.innerHTML = size;
/* Altering the hidden field values */
hiddenpricetag.setAttribute("value", "£"+finalPrice+".00");
hiddensize.setAttribute("value", size);
}
JSFiddle can be found here: http://jsfiddle.net/J4rXX/7/
Related
I want make option selected in dropdown html form, i am fetching data from database but into the html select cant get how to option selected
Below is the My database table data get. from that account holder is the my database value. I want to compare with select option nd make then selected into dropdown.
Array
(
[ipsf_public_pf_id] => 62
[ipsf_main_id] => 216
[account_no] => 54545455
[account_holder] => self
[pf_amt] => 1500.00
[date_of_payment] => 2020-11-15
)
and my html php form like this
$str .='<input type="hidden" name="ipsf_public_pf_id" value="<?php echo $ipsf_public_pf; ?>">
<table align="center" cellspacing="1" class="table table-bordered">
<tbody>
<tr>
<td>PPF A/c No</td>
<td>Account Holder</td>
<td>Date of Payment</td>
<td>Amount</td>
</tr>
<tr>
<td>
<input name="account_no_'.$ppf.'" type="text" id="account_no_'.$ppf.'" value="'.$account_no.'" size="20" maxlength="20" class="form-control" onkeyup="Validate_number(this)"/>
</td>
<td>
<select name="account_holder_'.$ppf.'" id="account_holder_'.$ppf.'" class="form-control">
<option value="" selected>Account Holder</option>
<option value="self">Self</option>
<option value="spouse">Spouse</option>
<option value="children">Children</option>
<!--<option value="others">Others</option>-->
</select>
</td>
<td>
<input name="date_of_payment_date_'.$ppf.'" id="date_of_payment_date_'.$ppf.'" maxlength="2" style="width: 50px;" type="text" onClick="this.value="";" value="'.$date.'" class="form-control-date" onkeyup="Validate_number(this)"/>-<input name="date_of_payment_month_'.$ppf.'" id="date_of_payment_month_'.$ppf.'" maxlength="2" style="width: 50px;" type="text" onClick="this.value="";" value="'.$month.'" class="form-control-date" onkeyup="Validate_number(this)"/>-<input name="date_of_payment_year_'.$ppf.'" id="date_of_payment_year_'.$ppf.'" maxlength="4" style="width: 65px;" type="text" onClick="this.value="";" value="'.$year.'" class="form-control-date" onkeyup="Validate_number(this)"/>
</td>
<td>
<input name="ppf_amt_'.$ppf.'" type="text" id="ppf_amt_'.$ppf.'" value="'.$pf_amt.'" size="10" onBlur="javascript:increment_ppf_amnt(this.value, '.$ppf.');" maxlength="14" class="form-control-date" onkeyup="Validate_number(this)"/>
<input type="hidden" name="prev_ppf_amount_'.$ppf.'" id="prev_ppf_amount_'.$ppf.'" value="'.$ppf.'"/>
<input type="hidden" name="is_added_0" id="is_added_0" value="no"/>
</td>
</tr>
</tbody>
<input type="hidden" name="total_ppf_amount" id="total_ppf_amount" value="0"/>
</table>';
I am confused how to selected that option inside .
Anyone know then please help me
On your html just fill the selected="<?=$selectedOption;?>.
Basically the logic behind it is: you fetch the data that you want to, and the values thaty ou on option tags you will gonna use the selected id / value or whatever that you want to use for in the selected atrribute on the <select></<select> html tag.
I'm trying to pass multiple values from same parameters of a form using POST, but can't figure out how to proceed. I've used bootstrap css such that I can add multiple products. And I want to process the data of multiple orders by passing the values using POST method.
On clicking 'Add another' link, additional set of data field appear which enables recording of multiple transactions of a same user.
The code is as follows:
<div class="col-xs-5 col-lg-offset-3">
<form action="billingProceed.php" method="post" role="form">
<table id="itemElement">
<tr>
<td>
<select class="form-control">
<option class="form-control"> Customer Name</option>
<option class="form-control"> Customer ID</option>
</select>
</td>
<td><input type="text" name="<?php echo $data["name"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td>
<select class="form-control">
<option class="form-control"> Item Name</option>
<option class="form-control"> Item ID</option>
</select>
</td>
<td ><input type="text" name="<?php echo $data["item"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Quantity
</td>
<td><input type="text" name="<?php echo $data["quantity"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Price
</td>
<td><input type="text" name="<?php echo $data["price"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Discount
</td>
<td><input type="text" name="<?php echo $data["discount"]; ?>" class="form-control" /></td>
</tr>
</table>
<input type="submit" value="Proceed" class="btn btn-primary" />
<p style="float:right;">Add another</p>
You can use an array name.
Example:
<input name="data['name'][1]">
<input name="data['name'][2]">
Firstly you should be aware of the name array, for input names.
HTML Example:
<form>
<a id="add_another" href="#">Add Another</a>
<table>
<tr class="product_item">
<td>
<input type="text" name="product[1][name]" value=""/>
</td>
<td>
<input type="text" name="product[1][item]" value=""/>
</td>
</tr>
<tr id="dummy">
<td>
<input type="text" name="product[0][name]" value=""/>
</td>
<td>
<input type="text" name="product[0][item]" value=""/>
</td>
</tr>
</table>
</form>
On POST, in your PHP script, you will access them as follows:
foreach($_POST['product'] as $product)
{
$name = $product['name'];
$item = $product['item'];
}
Shoot for the JS
//You'll always start with one product row.
var productCount = 1;
$('#add_another').click(function() {
var dummyproduct = $('#dummy').clone();
//Increment Product count
productCount += 1;
//Rename all inputs
dummyproduct.find('input[name^="product[0]"]').each(function(){
$(this).attr('name',$(this).attr('name').replace('product[0]','product['+productCount +']'));
});
//Remove Id from cloned dummy
dummyproduct.removeAttr('id').addClass('product_item');
//Insert row before Dummy
dummyproduct.insertBefore('#dummy');
});
I'm trying to send the option selected from a drop-down menu to a separate submit button. Here's my code so far:
<tr>
<td valign="top" style="width: 247px"><a href="action-amazon-sale.php?size=<?=$size?>&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>">
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON SOLD" style="width:100%" onclick="this.disabled=1;"/>
</a></td>
</tr>
<tr>
<td>
<form action="" style= "width: 250px" style="height: 38px; width: 350px">
<select name="shipping" class="button_select" style="width: 345px">
<option value="">SELECT SHIPPING FOR AMAZON & EBAY SALES</option>
<option value="0">FREE UK SHIPPING</option>
<option value="5.50">UK SHIPPING £ 5.50</option>
<option value="6.95">BOOTS SHIPPING £ 6.95</option>
<option value="14.95">EURO £ 14.95</option>
<option value="19.95">EURO 2 £ 19.95</option>
<option value="29.95">WORLD £ 29.95</option>
</select>
</form>
</td>
</tr>
</table></td>
</tr>
I want the user to first select a shipping option from the drop-down menu and upon clicking the 'AMAZON SOLD' submit button, have that value POST to the subsequent PHP page, i.e. action-amazon-sale.php ...
Can anybody please tell me how I should do this?
Thanks.
UPDATE #2
<tr>
<td valign="top" style="width: 247px"><a href="action-amazon-sale.php?size=<?=$size?>&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>">
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON SOLD" style="width:100%" form="shipping" formmethod="post"
formaction="action-amazon-sale.php?size=<?=$size?>&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>" onclick="this.disabled=1;"/>
</a></td>
<td width="530" align="right"></td>
</tr>
<td width="252" valign="top" style="height: 13px"><a href="action-amazon-sale.php?size=<?=$size?>_con_b&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>">
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON CONCESSION SOLD" style="width:100%" form="shipping" formmethod="post" formaction="action-amazon-sale.php?size=<?=$size?>_con_b&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>" onclick="this.disabled=1;"/>
</a></td>
<tr>
<form id="shipping">
<td valign="top">
<select name="shipping" class="button_select" style="width: 276px">
<option value="">SELECT SHIPPING FOR AMAZON SALES</option>
<option value="0">FREE UK SHIPPING</option>
<option value="16.95">EURO SHIPPING £ 16.95</option>
<option value="14.50">BOOTS SHIPPING € 17.50</option>
</select>
</form></td></tr>
<tr>
On the target URL I have written a short test i.e.
$shipping=$_POST['shipping'];
echo $shipping;
However, the result is blank. Where am I going wrong?
Thanks
You need to put the input button inside the form and method should be POST
<form method="POST" action="action-amazon-sale.php?size=<?= $size ?>&id=<?= $product['product_id']; ?>&barcode=<?= $barcode ?>&shop_price=<?= $product['price'] ?>&brand=<?= $product['brand_id'] ?>&title=<?= $product['title'] ?>&colour=<?= $product['colour'] ?>&shoe_id=<?= $product['shoe_id']; ?>" style= "width: 250px" style="height: 38px; width: 350px">
<table>
<tr>
<td valign="top" style="width: 247px">
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON SOLD" style="width:100%" onclick="this.disabled = 1;"/>
</td>
</tr>
<tr>
<td>
<select name="shipping" class="button_select" style="width: 345px">
<option value="">SELECT SHIPPING FOR AMAZON & EBAY SALES</option>
<option value="0">FREE UK SHIPPING</option>
<option value="5.50">UK SHIPPING £ 5.50</option>
<option value="6.95">BOOTS SHIPPING £ 6.95</option>
<option value="14.95">EURO £ 14.95</option>
<option value="19.95">EURO 2 £ 19.95</option>
<option value="29.95">WORLD £ 29.95</option>
</select>
</td>
</tr>
</table>
</form>
You id your form like this:
<form id="myform">
<input type="text" name="example" value="" />
</form>
And the submit button:
<input type="submit" value="submit" form="myform" />
OR if you want to define the method, if you define the formmethod in your submit button it will override the method defined in the <form> tag.
<input type="submit" value="submit" form="myform" formmethod="post" />
This indicate that the submit belongs to myform. I think this is HTML5 added attributes. Some browsers won't submit if the submit input is placed inside the form tags.
This attribute can be used for most if not all html input. This means you can have your input field placed outside the form but still belong to the form.
You can use your updated codes using separate form for each one. What you put in a href should be in the formaction.
<input type="submit" form="myform" formaction="action-amazon-sale.php?size=<?=$size?>&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>&colour=<?=$product['colour']?>&shoe_id=<?=$product['shoe_id'];?>"
Or you can just refer to one form. Like this:
<form id="shipping" style= "width: 250px" style="height: 38px; width: 350px">
<select name="shipping" class="button_select" style="width: 345px">
<option value="">SELECT SHIPPING FOR AMAZON & EBAY SALES</option>
<option value="0">FREE UK SHIPPING</option>
<option value="5.50">UK SHIPPING £ 5.50</option>
<option value="6.95">BOOTS SHIPPING £ 6.95</option>
<option value="14.95">EURO £ 14.95</option>
<option value="19.95">EURO 2 £ 19.95</option>
<option value="29.95">WORLD £ 29.95</option>
</select>
</form>
with your buttons, like this:
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON SOLD" style="width:100%" form="shipping" formmethod="post"
formaction="action-amazon-sale.php?size=<?=$size?>...." onclick="this.disabled=1;"/>
<input name="button5" type="submit" class="submit-button-green" id="button5" value="AMAZON SOLD" style="width:100%" form="shipping" formmethod="post"
formaction="action-amazon-sale.php?size=<?=$size?>_con_b&id=" onclick="this.disabled=1;"/>
My form is looking like this.
<form action="add_customers.php" method="post" onsubmit="MM_validateForm('name','','R','passport_no','','R','remarks','','R');return document.MM_returnValue">
<tr>
<td>Name of the Applicant:</td>
<td><label for="name"></label>
<input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Country applying for :</td>
<td><label for="country"></label>
<select name="country" id="country">
<option>Singapore</option>
<option>Malaysia</option>
<option>Istanbul</option>
<option>Thailand</option>
<option>China</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td>Visa Categeory :</td>
<td><label for="visa_categeory"></label>
<select name="visa_categeory" id="visa_categeory">
<option>Visit</option>
<option>Business</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td>Passport No:</td>
<td><input type="text" name="passport_no" id="passport_no" /></td>
</tr>
<tr>
<td>Remarks:</td>
<td><label for="remarks"></label>
<textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr></form>
Now My problem is
1) when a user select other option from Visa Category then automatically display a text box for user and capture that what he enter.
2) save that details into mysql database
Used languages are PHP,MYSQL
Thanks.
You can add a text box in your form and make it hidden first time.
Get the textbox visible on change of the dropdown you have mentioned using javascript.
You can get the value of the textbox in the page where you accepts the data and insert into data database in add_customers.php along with other variables.
<script>
function visacatOnchange(){
var visa_cat = document.getElementById('visa_categeory').value
if(visa_cat == "Visit")
document.getElementById("new_textbox").style.display="block";
else
document.getElementById("new_textbox").style.display="none";
}
</script>
In html form add
<input type="text" name="new_textbox" id="new_textbox" style="display:none;">
and change
<select name="visa_categeory" id="visa_categeory" onChange="visacatOnchange();">
Good luck :-)
Initially you can keep the textbox div hidden and then display it on "onchange" event of select input.
<div id="textboxdiv" style="visibility: hidden">
Visa Option <input type="text" id="someid"/>
</div>
<select name="visa_categeory" id="visa_categeory" onchange="showTextBox()" >
<option>Visit</option>
<option>Business</option>
<option value="99" >Other</option>
</select>
Using Jquery you can display it like this:-
function showTextBox(){
if ($('#visa_categeory').val() == '99') {
$('#textboxdiv').css({'visibility':'visible'});
}
Here's some basic JavaScript/jQuery that should help you solve your first problem: http://jsfiddle.net/j4aXQ/
HTML
<form>
<select name="visa_category">
<option>Visit</option>
<option>Business</option>
<option>Other</option>
</select>
</form>
JS
$('select').change(function() {
var $selected = $('select option:selected');
if ('Other' === $selected.text()) {
$('form').append($('<input>').prop({'type':'text','id':'visa_other','name':'visa_other'}));
$('form').append($('<label>').prop({'for':'visa_other'}).html('Testing'));
} else {
$('input').remove();
$('label').remove();
}
});
The above code will only display a text box (and accompanying label) if the "Other" option is selected, and will then remove that text box if a different option is subsequently picked.
Hope that helps!
<div id="form1" />
<form name="choice">
<table>
<tr>
<td>
Number of new types you want to add
</td>
<td>
<select name="<?php echo $num; ?>">
<option value="1" selected>1 row</option>
<option value="2">2 rows</option>
<option value="3">3 rows</option>
<option value="4">4 rows</option>
<option value="5">5 rows</option>
</select>
<div class='inputs'></div>
</td>
</tr>
</table>
</form>
<form name="myForm" action="addAccessories.php" method="post" onsubmit="return validateForm(this);">
<table border="1">
<tr>
<th>Barcode<em>*</em></th>
<th>Description<em>*</em></th>
<th>Minimum required stock<em>*</em></th>
<th>Current stock</th>
</tr>
<?php
echo $num;
?>
<tr>
<td><input type="text" name="bar_code/></td>
<div class="ui-widget">
<td><input name="description/></td>
</div>
<td><input type="text" name="minimum_required_stock" /></td>
<td><input type="text" name="num_stock" value="0"></td>
<tr>
<td> </td>
<td> <button data-theme="b" id="submit" type="submit">Add accessories</button></td>
</tr>
</table>
</form>
Hello guys,
In this code I have 2 form, 1 is the drop box has 5 options and a form for text input.
In theory, if I choose option value="3", the text form will be loop 3 times and get 3 set of text inputs. However, I haven't succeeded in doing this by far. And also, how can I access these 3 sets of data in addAccessories.php file?
I appreciate any opinion on this topic.
Thank you very much.
Reading your question, it sounds like you want to have code such that when the selection in form choice changes, you change the number of rows in form myform. This is not possible from php because it will be a runtime change on the client machine. You can write this in javascript. You will need code called from form choice that adjusts the DOM in form myform.
You can either use a pure PHP solution and rebuild the page - but that's clunky and slow (which, might be fine for a pet project). Normally we'd use Javascript with AJAX to accomplish something like this.