Pete Winter
asked on
jQuery Selecting ID with forward slash
My code below does not work if the ID has a forward slash in the name. I have read you have to escape special characters with a double backslash, but my data comes from a database. Is there a formula that adds a double back slash if a forward slash is found?
var sup_code = $(this).attr('id');
var sup_code = $(this).attr('id');
// Start of Price Override Change
$('.ListResults').on('click','.Change_Price', function(event) {
event.preventDefault();
var sup_code = $(this).attr('id');
var current_cost = $(this).text().replace('£', '');
$.post("ink_override_script.php", {
cust_id: $('#cust_id').text(),
supplier_code: sup_code,
price_override: $(this).attr('rel')
}, function(data) {
$("#" + sup_code).hide();
$("#Price_Editing-" + sup_code).html(data).show();
$('.loadingDiv').hide();
$('.ListResults').on('click','.SavePrice', function(event) {
if( $('.price_overrider-' + sup_code).val() != current_cost )
{
if( $("#" + sup_code).hasClass('price_override')) {
$.post("ink_override_update_script.php", {
cust_id: $('#cust_id').text(),
supplier_code: sup_code,
price_override_update: $('.price_overrider-' + sup_code).val(),
}, function(data) {
$('.loadingDiv').hide();
$("#" + sup_code).text($('.price_overrider-' + sup_code).val()).show().addClass('price_override');
var amount = $("#" + sup_code).text();
$("#" + sup_code).text("£" + amount);
$("#" + sup_code).attr('rel', amount);
$("#Price_Editing-" + sup_code).hide();
$('.price_overrider-' + sup_code).toggleClass( 'disabled' );
});
} else {
$.post("ink_override_insert_script.php", {
cust_id: $('#cust_id').text(),
supplier_code: sup_code,
price_override_update: $('.price_overrider-' + sup_code).val(),
}, function(data) {
$('.loadingDiv').hide();
$("#" + sup_code).text($('.price_overrider-' + sup_code).val()).show().addClass('price_override');
var amount = $("#" + sup_code).text();
$("#" + sup_code).text("£" + amount);
$("#" + sup_code).attr('rel', amount);
$("#Price_Editing-" + sup_code).hide();
$('.price_overrider-' + sup_code).toggleClass( 'disabled' );
});
}
} else {
$('.loadingDiv').hide();
$("#" + sup_code).show();
$("#Price_Editing-" + sup_code).hide();
}
});
});
});
// End of Price Override Change
My first question is why do you have a forward slash in your ID's - personally I would try and fix that than try and work around it.
ASKER
The ID's are product codes and are unique identifiers.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Many thanks
ASKER