Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14524
  • Last Modified:

Jquery SubString Idea??

Hi Experts

I've already posted a question relating to this which has been answered perfectly but i didn't want to be cheeky and add this onto it so there are more points available for completing this.

Previous link is as follows:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_23842721.html

Anyway i'm using the following code to add the value of (#idBox) to the option values of a select box (#itemname):

$(document).ready(function(){
$("#submit").click(function(){
 
$('#itemname option').each(function(){$(this).val($(this).val() + $('#idBox').val());});
 
return false;
});
});

That works perfectly as initially required; i have something additional that has only just reared it's head to this; any chance you can show me how i can combine this idea but set more precisely where i put the value of the (#idBox) textbox? I'm thinking subString sort of thing but essentially my option value code looks as follows:

<option value="(1 month) {75.00}">1 month - £75.00</option>

The {75.00} is needed for the shopping cart but if i use the a code above  it adds the (#idBox) value at the end and the shopping cart for some annoying reason needs the {75.00} to be the last thing in the option value code.

I'd like to be able to set the addition of (#idBox) value to be 9 characters in from the end (ie before the {75.00}.

500 points available for this...

Cheers
0
pixelcellar
Asked:
pixelcellar
1 Solution
 
sh0eCommented:

$(document).ready(function(){
$("#submit").click(function(){
 
$('#itemname option').each(function(){$(this).val($(this).val().replace(/(\(.*\))/,'$1' + $('#idBox').val()));});
 
return false;
});
}); 

Open in new window

0
 
pixelcellarAuthor Commented:
Legendary; many thanks for that!!!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now