Solved

Jquery SubString Idea??

Posted on 2008-10-24
2
14,514 Views
Last Modified: 2012-06-27
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
Comment
Question by:pixelcellar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22796014

$(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
 

Author Comment

by:pixelcellar
ID: 22796155
Legendary; many thanks for that!!!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question