I know the examples are differing but thats because the js is mixing up however if the vat is show on both the examples and showing the issue i am having....
first example vat is fine, but second your see its showing as 0.20 and i think s not working correctly when over 1000.... anyone know why when over 1000 does not calculate the 20% correctly?
$(document).ready(function() {
// Hide initial values that need updating
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").hide();
// get current delivery rate
$("#get_rate").trigger('click');
// set a timeout and get total and shipping that was generated and add together for nnew total
setTimeout(function() {
// get cart sub-total
var a = $(".cart-total span").text().replace(/\$|£/gi, "");
// get estimated shipping cost
var b = $("#estimated-shipping em").text().replace(/\$|£/, '');
if (b == "FREE") {
b = "0.00"
var isFree = "true";
} else {
b = $("#estimated-shipping em").text().replace(/\$|£/, '');
}
// add together sub-total and estimated shipping to new total
var total = a + b;
total = parseFloat(total.replace(/,/g, ''));
//add the currency with £ (not sure why it was setting $ before)
if (isFree == "true") {
$("#estimated-shipping em").html("FREE");
} else {
$("#estimated-shipping em").html("£" + b);
}
// update with new total with sub-total and added shipping
$('.cart-finalTotal span').html("£" + total.toFixed(2).replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,'));
// show new values
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").show();
}, 2000);
$(".item-quantity input").on("change", function() {
// let initially disable the input to avoid problems
$(".item-quantity input").prop("disabled", true);
// gets auto get rates based on a UK address
$("#get_rate").trigger('click');
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").hide();
setTimeout(function() {
var a = $(".cart-total span").text().replace(/\$|£/gi, "");
// get estimated shipping cost
var b = $("#estimated-shipping em").text().replace(/\$|£/, '');
if (b == "FREE") {
b = "0.00"
var isFree = "true";
} else {
b = $("#estimated-shipping em").text().replace(/\$|£/, '');
}
// add together sub-total and estimated shipping to new total
var total = a + b;
total = parseFloat(total.replace(/,/g, ''));
//add the currency with £ (not sure why it was setting $ before)
if (isFree == "true") {
$("#estimated-shipping em").html("FREE");
} else {
$("#estimated-shipping em").html("£" + b);
}
// update with new total with sub-total and added shipping
$('.cart-finalTotal span').html("£" + total.toFixed(2).replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,'));
// update VAT when input changed
var oldVAT = $(".cart-total span").text().replace(/\$|£/gi, "");
var newVAT = (parseFloat(oldVAT.replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,')) * 20) / 100;
$(".cart-vat span").html("£" + newVAT.toFixed(2));
// show all new value updates
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").show();
// lets enable the quantity input a gain
$(".item-quantity input").prop("disabled", false);
}, 2000);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>under 1000</h1>
<form action="/cart" method="POST">
<div class="cart-left">
<table class="cart-items">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Sub-total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr data-variant-id="16285032007">
<td class="item-details">
<a href="/products/avatar-aubergine-dream-1?variant=16285032007" class="item-thumbnail">
<img src="//cdn.shopify.com/s/files/1/1174/5686/products/Avatar-aubergine-dream_011b6ba4-8681-4969-aad2-fcfc7c83121a_small.jpeg?v=1456749751" alt="Avatar - Aubergine Dream - Cover + Bean Filling (UK only)">
</a>
<div class="item-info">
<p class="item-brand" style="width:30px;"></p>
<div class="product-brand" itemprop="brand">
<a href="/collections/vendors?q=Avatar%20Indoor">
<img src="//cdn.shopify.com/s/files/1/0911/4528/t/5/assets/logo-Avatar.jpg" style="width:100px!important">
</a>
</div>
<p></p>
<p class="item-title">Aubergine Dream
</p>
<p class="item-variant">Cover + Bean Filling (UK only)</p>
</div>
</td>
<td class="item-price">
<span class="show-mobile"> PRICE :</span>
<span class="money">£199.00</span>
</td>
<td class="item-quantity">
<input type="number" pattern="[0-9]*" maxlength="4" value="7" data-variant-id="16285032007">
</td>
<td class="item-line-price">
<span class="show-mobile">SUB-TOTAL :</span>
<span class="money" data-currency="GBP">£398.00</span>
</td>
<td class="item-remove">
<i class="icon-cross"></i>
</td>
</tr>
</tbody>
</table>
Continue Shopping
<div class="cart-instructions">
<p>
<label for="cart-note">Add a note to your order</label>
<textarea id="cart-note" rows="4" name="note"></textarea>
</p>
</div>
</div>
<div class="cart-right">
<p class="cart-total">Sub-Total<span class="money" data-currency="GBP">£398.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money" style="display: block;">£79.60</span>
</p>
<p class="cart-delivery">Delivery (estimated)<span class="money" id="estimated-shipping">+ <em style="display: inline;">£9.00</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money" style="display: block;">£398.01</span>
</p>
<div class="cart-checkout">
<button class="button button-primary button-add-to-cart button-pay-now" type="submit" name="checkout"><span class="icom-lock"></span>Pay Now</button>
<br>
<br>
<div class="additional-checkout-buttons">
<p>Or checkout with</p>
<img id="applePayButton" style="display: none" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="typeof createApplyPayButton === 'function' ? createApplyPayButton(this) : window.addEventListener('applePayReady', (function(){createApplyPayButton(this)}).bind(this))">
<input type="image" name="goto_pp" value="paypal_express" src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif">
</div>
</div>
</div>
</form>
<h1>over 1000</h1>
<form action="/cart" method="POST">
<div class="cart-left">
<table class="cart-items">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Sub-total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr data-variant-id="16285032007">
<td class="item-details">
<a href="/products/avatar-aubergine-dream-1?variant=16285032007" class="item-thumbnail">
<img src="//cdn.shopify.com/s/files/1/1174/5686/products/Avatar-aubergine-dream_011b6ba4-8681-4969-aad2-fcfc7c83121a_small.jpeg?v=1456749751" alt="Avatar - Aubergine Dream - Cover + Bean Filling (UK only)">
</a>
<div class="item-info">
<p class="item-brand" style="width:30px;"></p>
<div class="product-brand" itemprop="brand">
<a href="/collections/vendors?q=Avatar%20Indoor">
<img src="//cdn.shopify.com/s/files/1/0911/4528/t/5/assets/logo-Avatar.jpg" style="width:100px!important">
</a>
</div>
<p></p>
<p class="item-title">Aubergine Dream
</p>
<p class="item-variant">Cover + Bean Filling (UK only)</p>
</div>
</td>
<td class="item-price">
<span class="show-mobile"> PRICE :</span>
<span class="money">£199.00</span>
</td>
<td class="item-quantity">
<input type="number" pattern="[0-9]*" maxlength="4" value="7" data-variant-id="16285032007">
</td>
<td class="item-line-price">
<span class="show-mobile">SUB-TOTAL :</span>
<span class="money" data-currency="GBP">£1,194.00</span>
</td>
<td class="item-remove">
<i class="icon-cross"></i>
</td>
</tr>
</tbody>
</table>
Continue Shopping
<div class="cart-instructions">
<p>
<label for="cart-note">Add a note to your order</label>
<textarea id="cart-note" rows="4" name="note"></textarea>
</p>
</div>
</div>
<div class="cart-right">
<p class="cart-total">Sub-Total<span class="money" data-currency="GBP">£1,194.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money" style="display: block;">£0.20</span>
</p>
<p class="cart-delivery">Delivery (estimated)<span class="money" id="estimated-shipping">+ <em style="display: inline;">FREE</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money" style="display: block;">£1,194.00</span>
</p>
<div class="cart-checkout">
<button class="button button-primary button-add-to-cart button-pay-now" type="submit" name="checkout"><span class="icom-lock"></span>Pay Now</button>
<br>
<br>
<div class="additional-checkout-buttons">
<p>Or checkout with</p>
<img id="applePayButton" style="display: none" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="typeof createApplyPayButton === 'function' ? createApplyPayButton(this) : window.addEventListener('applePayReady', (function(){createApplyPayButton(this)}).bind(this))">
<input type="image" name="goto_pp" value="paypal_express" src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif">
</div>
</div>
</div>
</form>
Related
I have table that is populated with items from a database. There is a column to "tick" each item, which calls to the database to change the status of that item to "Valid" - that part works. To save me having to refresh the page though, I would like to then update the text on the page after the ajax call so that it reads "Valid" instead of submitted. What is the correct code to achieve this? Where am I going wrong? Without success, I have also attempted to get the tick to go green once clicked.
<div class="form-group">
<div class="row">
<div class="table-responsive col-md-6">
<h4><i class="glyphicon glyphicon-check"></i> Summary</h4>
<hr />
<table id="stationCount" class="table table-bordered table-hover">
<tr>
<th>ID</th>
<th>Place</th>
<th>Submission Date</th>
<th>Status</th>
<th>Confirm</th>
</tr>
<tr>
<td>
<p id="lblId" class="form-control-static" contenteditable="false">
159
</p>
</td>
<td>
<p id="lblPlaceName" class="form-control-static" contenteditable="false">
Somewhere
</p>
</td>
<td>
<input type="hidden" data-val="true" data-val-required="The SurveyId field is required." id="Items_0__SurveyId" name="Items[0].SurveyId" value="159" />
<p id="lblSubmittedOn" class="form-control-static" contenteditable="false" title="27/03/2018 11:04:47">
27/03/2018
</p>
</td>
<td class="status" id="159">
<p asp-for="Submitted">
Submitted
</p>
</td>
<td>
<a href='#' class='btn btn-default ConfirmLink' style="color: #808080 " data-url='/Controller/ValidateSurvey' data-id="159">
<i class="fa fa-check"></i>
</a>
</td>
</tr>
<tr>
<td>
<p id="lblId" class="form-control-static" contenteditable="false">
3
</p>
</td>
<td>
<p id="lblPlaceName" class="form-control-static" contenteditable="false">
Somewhere else
</p>
</td>
<td>
<input type="hidden" data-val="true" data-val-required="The SurveyId field is required." id="Items_5__SurveyId" name="Items[5].SurveyId" value="3" />
<p id="lblSubmittedOn" class="form-control-static" contenteditable="false" title="21/01/2018 00:00:00">
21/01/2018
</p>
</td>
<td class="status" id="3">
<p asp-for="Submitted">
Expired
</p>
</td>
<td>
<a href='#' class='btn btn-default ConfirmLink' style="color: #808080" data-url='/Controller/ValidateSurvey' data-id="3">
<i class="fa fa-check"></i>
</a>
</td>
</tr>
</table>
</div>
</div>
</div>
$(function() {
//Document.ready//
//link up event handler
$(".ConfirmLink").click(function() {
// Get the id from the link
var recordToConfirm = $(this).attr("data-id");
var postToUrl = $(this).attr("data-url");
$.ajax(postToUrl, {
type: "post",
data: {
"id": recordToConfirm
},
dataType: "json"
}).done(function(data) {
// Successful requests get here
});
if ($(this).css('color') === '#808080') {
$(this).css('color', '#008000');
} else {
$(this).css('color', '#808080');
}
$("#" + recordToConfirm + " td.status").html('Valid');
});
});
I have set up a jsfiddle:
https://jsfiddle.net/a4zhpt7L/4/
To do everything you want, change some things:
Change if ($(this).css('color') === '#808080') to if ($(this).css('color') == 'rgb(128, 128, 128)'), because jQuery returns a rgb code instead of a hex code.
Change $("#" + recordToConfirm + " td.status").html('Valid'); to $("td.status#" + recordToConfirm).html('Valid');, because the td.status was placed incorrectly.
I hope this also fixes your ajax problem.
I have a shopping cart and a page that shows all products in a table. I am able to remove products, but I want to be able to change their quantity as well.
My table consists of an input field that you can change the quantity in, when clicking on an 'update' cart button below, I am sending the productname and the quantity to my PHP script. The problem is, it always posts the first product.
Probably because all have the same classname, how can I fix that?
This is what my table looks like:
<div class="col-md-8">
<div class="kl-title-block clearfix text-left tbk-symbol--line tbk-icon-pos--after-title">
<h2 class="tbk__title montserrat fs-34 fw-semibold black winkelmandtitle">Uw Winkelmand</h2>
<span class="tbk__symbol ">
<span></span>
</span>
<h4 class="tbk__subtitle fs-22 fw-thin">Bent u niets vergeten?</h4>
</div>
<div class="table-responsive">
<table class="table carttable">
<thead>
<tr>
<th>Verwijder</th>
<th>Afbeelding</th>
<th>Product</th>
<th>Prijs</th>
<th>Aantal</th>
<th>Totaal</th>
</tr>
</thead>
<tbody>
<tr>
<td>×</td>
<td>
<a href="baden/bad-13" class="product-title">
<img class="attachment-shop_thumbnail" src="images/defaultimage.jpg" alt="Bad 13" title="Bad 13">
</a>
</td>
<td>
<a href="baden/bad-13" class="product-title">
Bad 13
</a>
</td>
<td>€ 1500</td>
<td>
<div class="quantity">
<input type="number" step="1" min="0" name="quantity" id="Bad 13" value="1" title="Qty" class="input-text qty quantityclass text" size="4">
</div>
</td>
<td>€ 1500</td>
</tr>
</tbody>
<tbody>
<tr>
<td>×</td>
<td>
<a href="baden/bad-14" class="product-title">
<img class="attachment-shop_thumbnail" src="images/defaultimage.jpg" alt="Bad 14" title="Bad 14">
</a>
</td>
<td>
<a href="baden/bad-14" class="product-title">
Bad 14
</a>
</td>
<td>€ 800</td>
<td>
<div class="quantity">
<input type="number" step="1" min="0" name="quantity" id="Bad 14" value="1" title="Qty" class="input-text qty quantityclass text" size="4">
</div>
</td>
<td>€ 800</td>
</tr>
</tbody>
<tbody>
<tr>
<td>×</td>
<td>
<a href="baden/bad1" class="product-title">
<img class="attachment-shop_thumbnail" src="cms/images/bad.jpg" alt="Bad 1" title="Bad 1">
</a>
</td>
<td>
<a href="baden/bad1" class="product-title">
Bad 1
</a>
</td>
<td>€ 1000</td>
<td>
<div class="quantity">
<input type="number" step="1" min="0" name="quantity" id="Bad 1" value="1" title="Qty" class="input-text qty quantityclass text" size="4">
</div>
</td>
<td>€ 1000</td>
</tr>
</tbody>
</table>
<input type="submit" class="button updatebutton" name="update_cart" value="Wijzig winkelmand">
</div>
</div>
And this is my jquery script that fires an ajax post.
//Wijzig winkelmand met het aantal producten
tpj('.cartsection').on('click', '.updatebutton', function(event) {
var $edit = tpj('.quantityclass').attr('id'),
$aantal = tpj('.quantity').find( "input[name='quantity']" ).val(),
url = 'includes/cartoverzicht.php';
var posting = tpj.post( url, { edit: $edit, aantal: $aantal} );
posting.done(function( data ) {
var content = tpj( data );
tpj( "#cartresult" ).empty().append( content );
});
});
The problem is, when I look in network this is always posted no matter what product I clicked:
edit:Bad 13
aantal:1
How can I fix that?
Can I maybe post all quantities to my php script? What would be the best solution?
You are hitting problems because you are only ever grabbing the first selector. You have also designed your API to only send one update when it looks like you want to send the whole updated set.
Below is the way to go if you want to update the quantities for the whole cart.
$('.updatebutton').on('click', function(event) {
var elements = $('.quantity input[name="quantity"]'),
url = 'includes/cartoverzicht.php',
postBody = [];
for (var i=0; i<elements.length; i++) {
var element = $(elements[i]);
postBody.push({
edit: element.attr('id'),
aantal: element.val()
})
}
var posting = $.post( url, JSON.stringify(postBody) );
posting.done(function( data ) {
var content = $( data );
$( "#cartresult" ).empty().append( content );
});
});
The issue is here:
var $edit = tpj('.quantityclass').attr('id'),
you are using a class selector to get the value, it always return the first element value. Instead use this
See this example:
$(document).ready(function(){
$('.list').click(function(){
console.log( $('.list').html() );
});
$('.listing').click(function(){
console.log( $(this).html() );
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
First list (It always return the first element value)
</p>
<li class="list">One</li>
<li class="list">Two</li>
<li class="list">Three</li>
<p>
Another List (It always return the clicked element value)
</p>
<li class="listing">One</li>
<li class="listing">Two</li>
<li class="listing">Three</li>
I tried to use this issue as a guide, but I'm not sure what I'm doing wrong with my below code. I'd appreciate it if someone could help out.
A little background: I have limited ability to change the HTML as it's in Confluence using an add-on called Confiforms. I can hide/show fields using Confiforms, but I generally find that it takes a performance hit when I configure it that way.
HTML:
<tr>
<td class="label editLabel">Customer Impact?</td>
<td>
<p class="auto-cursor-target">
<span class="i_holdingrow_impact">
<span id="i_holdingrow_impact">
<input cf-field="impact" class="radio" type="checkbox" name="impact" id="i_impact">
</span>
</span>
</p>
</td>
</tr>
<tr>
<td/>
<td>
<p>
<span class="i_holdingrow_impactDesc">
<span id="i_holdingrow_impactDesc">
<textarea cf-field="impactDesc" id="i_impactDesc" name="impactDesc" rows="4" class="textarea large-field cf_textarea"/>
</span>
</span>
</p>
</td>
</tr>
Relevant jQuery:
$('input[type="checkbox"]').change(() => {
if ($(this).is(':checked')) {
$(this).closest('tr').next('tr').show();
}
else {
$(this).closest('tr').next('tr').hide();
}
});
Thanks!
You should be very careful when using jquery with arrow functions:
$('input[type="checkbox"]').change(function() {
if ($(this).is(':checked')) {
$(this).closest('tr').next('tr').show();
} else {
$(this).closest('tr').next('tr').hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="label editLabel">Customer Impact?</td>
<td>
<p class="auto-cursor-target">
<span class="i_holdingrow_impact">
<span id="i_holdingrow_impact">
<input cf-field="impact" class="radio" type="checkbox" name="impact" id="i_impact">
</span>
</span>
</p>
</td>
</tr>
<tr>
<td/>
<td>
<p>
<span class="i_holdingrow_impactDesc">
<span id="i_holdingrow_impactDesc">
<textarea cf-field="impactDesc" id="i_impactDesc" name="impactDesc" rows="4" class="textarea large-field cf_textarea"></textarea>
</span>
</span>
</p>
</td>
</tr>
</table>
The arrow-function preserve the context of this, thus it's no longer the relevant element you attached the event to.
In case you do want to use arrow function, you can use the following:
$('input[type="checkbox"]').change((evt) => {
el = evt.currentTarget;
if ($(el).is(':checked')) {
$(el).closest('tr').next('tr').show();
} else {
$(el).closest('tr').next('tr').hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="label editLabel">Customer Impact?</td>
<td>
<p class="auto-cursor-target">
<span class="i_holdingrow_impact">
<span id="i_holdingrow_impact">
<input cf-field="impact" class="radio" type="checkbox" name="impact" id="i_impact">
</span>
</span>
</p>
</td>
</tr>
<tr>
<td/>
<td>
<p>
<span class="i_holdingrow_impactDesc">
<span id="i_holdingrow_impactDesc">
<textarea cf-field="impactDesc" id="i_impactDesc" name="impactDesc" rows="4" class="textarea large-field cf_textarea"></textarea>
</span>
</span>
</p>
</td>
</tr>
</table>
Tried to get the text box value and display into the h3 element in above the textbox field
Here is my HTML Code :
<div class="clonedInput" id="add_attribute" style="display: block;">
<div id="add_attributes">
<div id="accordion1">
<h3>
<input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
<strong class="attribute_name">**Here Text box value should be displayed**</strong> </h3>
<table cellspacing="0" cellpadding="0" id="attribute_data" class="">
<tbody>
<tr>
<td class="attribute_name"><label>Name:</label>
<input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
</td>
<td rowspan="3"><label>Value(s):</label>
<textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="clonedInput" id="add_attribute_2" style="display: block;">
<div id="add_attributes" class="woocommerce_attribute wc-metabox ">
<div id="accordion1">
<h3>
<input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
<strong class="attribute_name"></strong> </h3>
<table cellspacing="0" cellpadding="0" id="attribute_data" class="">
<tbody>
<tr>
<td class="attribute_name"><label>Name:</label>
<input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
</td>
<td rowspan="3"><label>Value(s):</label>
<textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="clonedInput" id="add_attribute_3" style="display: block;">
<div id="add_attributes" class="woocommerce_attribute wc-metabox ">
<div id="accordion1">
<h3>
<input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
<strong class="attribute_name"></strong> </h3>
<table cellspacing="0" cellpadding="0" id="attribute_data" class="">
<tbody>
<tr>
<td class="attribute_name"><label>Name:</label>
<input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
</td>
<td rowspan="3"><label>Value(s):</label>
<textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
I'm trying to get the input field value <input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]"> and display the value into the "
<h3>
<input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
<strong class="attribute_name">"**Here the text box value"</strong> </h3>
" on blur function and this was dynamic text box
My Jquery :
$( "input" ).blur(function() {
var string = $(this).val();
$(this).parent().append(string);
});
I added an id attribute to the h3 where you want to display it and use that as reference on the blur event callback: DEMO HERE
HTML
<strong class="attribute_name" id="output">**Here Text box value should be displayed**</strong> </h3>
jQuery
$("input").blur(function () {
var string = $(this).val();
$('#output').html(string);
});
See a working demo here: http://jsfiddle.net/wPCZ5/
You need to do this in your handler:
$(this).closest('div').find('h3 > strong').html(string);
for all text boxes to work. The closest() call looks up the DOM hierarchy and returns the first matching element. In your case, it is the accordion div. The find() call then looks down the DOM hierarchy for the matching element. Finally html() replaces the current HTML within the element with the supplied string. Your original call to append() would add the string to whatever is already present.
There's a working fiddle here: http://jsfiddle.net/u63CU/ but I think you should not reuse class and ID names like you have. It can lead to many undesired results, as jquery selects by id or class name.
<div class="clonedInput" id="add_attribute" style="display: block;">
<div id="add_attributes">
<div id="accordion1">
<h3>
<input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
<strong id="text-value" class="attribute_name">**Here Text box value should be displayed**</strong> </h3>
<table cellspacing="0" cellpadding="0" id="attribute_data" class="">
<tbody>
<tr>
<td class="attribute_name"><label>Name:</label>
<input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
</td>
<td rowspan="3"><label>Value(s):</label>
<textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
</div>
$( "#attribute_name" ).blur(function() {
var string = $(this).val();
$('#text-value').text(string);
});
try something like this
$( "input" ).blur(function() {
$(this).closest('strong.attribute_name').text(this.value);
});
If you want to place text box value in place of **Here Text box value should be displayed**, please try this:
$( "input" ).blur(function() {
var string = $(this).val();
$(".attribute_name").text(string);
});
I have the following code, basically it is performing two operations. First one being submitting my form data to the google spreadsheet and the other operation is submitting my second form textbox value data to another page textbox value. How to do this?
<script type="text/javascript">
<!--
function copy_data(val){
var a = document.getElementById(val.id).value
document.getElementById("copy_to").value=a
}
//-->
</SCRIPT>
<style type="text/css">
<!-- -->
</style>
</head>
<body>
<script type="text/javascript">var submitted=false;</script>
<iframe name="response_iframe" id="hidden_iframe" style="display:none;" onload="if(submitted){window.location='Thanks.asp';}"/>
<form action="https://docs.google.com/spreadsheet/formResponse?formkey=dGtzZnBaYTh4Q1JfanlOUVZhZkVVUVE6MQ&ifq" method="post" target="response_iframe" id="commentForm" onSubmit="submitted=true;">
<!-- #include virtual="/sts/include/header.asp" -->
<!-- ABove this Header YJC -->
<table style="background-color: #FFC ;" width="950" align="center" border="0" summary="VanaBhojnaluBooking_Table">
<tr>
<td colspan="7">
<p class="MsoNormal" align="center" style="text-align:center;">
<strong>
<span style="line-height:115%; font-family:'Arial Rounded MT Bold','sans-serif'; font-size:16.0pt; color:#76923C; ">Karthika Masa Vanabhojanalu – Participation Booking</span>
</strong>
</p>
<p class="MsoNormal" align="center" style="text-align:center;">
<strong>
<em>
<span style="line-height:115%; font-size:20.0pt; color:#7030A0; ">13<sup>th</sup> Nov 2011 - # West Coast Park - Singapore</span>
</em>
</strong>
</p>
<p class="MsoNormal" align="center" style="text-align:center;">
<strong>
<span style="color:#7030A0; ">Reserve your participation and avail </span>
<span style="color:red; ">
<a target="_blank" href="/STS/programs/VB_2011_info.asp"> DISCOUNT </a>
</span>
<span style="color:#7030A0; "> on the ticket</span>
</strong>
</p>
</td>
</tr>
<tr>
<th width="37" scope="col"> </th>
<th width="109" rowspan="5" valign="top" class="YJCRED" scope="col">
<div align="left">
<font size="2"> * Required</font>
</div>
</th>
<td width="68" scope="col">
<div align="right">
<font size="2.5px">Name</font>
<span class="yj">
<span class="yjcred">*</span>
</span>
</div>
</td>
<th colspan="3" scope="col">
<label for="Name"/>
<div align="left">
<input name="entry.0.single" class="required" style="width:487px; height:25px; vertical-align:middle;" type="text" id="entry_0" title="Enter your name">
</div>
</th>
<th width="223" scope="col"> </th>
</tr>
<tr>
<td> </td>
<td>
<div align="right">
<font size="2.5px">Phone</font>
<span class="yj">
<span class="yjcred">*</span>
</span>
</div>
</td>
<td width="107">
<input name="entry.1.single" class="required" title="Handphone Number with out +65" maxlength="8" style="width:100px;height:25px;" type="text" onkeyup="copy_data(this)" onKeyPress="return numbersonly(this, event)" id="entry_1"/>
<td width="170">
<div align="right">
<font size="2.5px">Email</font>
<span class="yj">
<span class="yjcred1">*</span>
</span>
</div>
</td>
<td width="206">
<input name="entry.2.single" type="text" style="width:190px;height:25px;" id="required" title="Enter your email address" class="required email"/>
</tr>
<tr>
<td> </td>
<td>
<div align="right">
<font size="2.5px">Home Phone</font>
</div>
</td>
<td width="107">
<input name="entry.1.single" title="Handphone Number with out +65" maxlength="8" style="width:100px;height:25px;" type="text" onKeyPress="return numbersonly(this, event)" id="entry_100"/>
</tr>
<tr>
<td align="center" colspan="7">
<p> </p>
<p>
<input type="submit" name="submit" onMouseOver="Window.status='You can not see anything';return true" onMouseOut="window.status='Press SUBMIT only after proper inforatmion entering then you are Done'" onClick="jQuery.Watermark.HideAll();" value="Submit">
</p>
<p> </p>
</td>
</tr>
<p> </p>
<tr>
<td colspan="25"/>
</tr>
</table>
</form>
<form method="Link" Action="Sankranthi_Reserv2.asp">
<input disabled name="copy of hp" maxlength="8" style="width:100px;height:25px;" type="text" id="copy_to">
</form>
<p>
<!-- #include virtual="/sts/include/footer.asp" -->
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<script type="text/javascript">
(function() {
var divs = document.getElementById('ss-form').getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className=='errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i=0; i < numDivs; i++) {
var div = divs[i];
if (div.className=='ss-form-entry' && div.firstChild && div.firstChild.className=='ss-q-title') {
div.lastChild.focus();
return;
}
}
As you can see from above, this is the first page and in the second page where I was referring to Sankranthi_Reserv2.asp in the second form. I want to pass the textbox value over there, so the problem is the first form is submitting to the google docs and storing the data, but the second form need to pass the handphone number textbox value to the nextpage textbox value, but there is only one SUBMIT button.
Something like this would work:
$('#form1_submit_button').click(function(){
$('form').each(function(){
$(this).submit();
});
});
Alternative:
$('#form1_submit_button').click(function(){
$('#form1 #form2 #form3').submit();
});
For submitting two forms you will have to use Ajax. As after using form.submit() page will load action URL for that form. so you will have to do that asynchronously.
So you can send both request asynchronously or send one request asynchronously and after its success submit second form.
function submitTwoForms() {
var dataObject = {"form1 Data with name as key and value "};
$.ajax({
url: "test.html",
data : dataObject,
type : "GET",
success: function(){
$("#form2").submit(); //assuming id of second form is form2
}
});
return false; //to prevent submit
}
You can bind this submitTwoForms() function on your that one submit button. Using
$('#form1').submit(function() {
submitTwoForms();
return false;
});
But, if you do not want to do all this, you can use Jquery form plugin to submit form using Ajax.
the simplest way I have found is something like this
<form method='post' action='whatever?whatever1=blah&whatever2=blah'>
<?php
header ("Location: http://example.com/whatever.html");
?>
This will do the action of the form (without showing it in your browser), then redirect to the page of the header.