Gaurav_0093
Gaurav_0093

Reputation: 1030

To get string from selected text in javascript?

I am using dropdown list to get the selected text value here is my code

var priceValue = $("#ddlprice option:selected").text();

and i am getting value like Basic Cotton Ultra ($20.05)

I just want Basic Cotton Ultra from the value so how can i extract this.

Upvotes: 0

Views: 65

Answers (2)

Vinod kumar G
Vinod kumar G

Reputation: 655

just split it before '(' and you will get the output..

var pricevalue = "Basic Cotton Ultra ($20.05)";
pricevalue = pricevalue.split('(')[0].trim();
//output will be "Basic Cotton Ultr

Upvotes: 1

Bourbia Brahim
Bourbia Brahim

Reputation: 14712

Just use Regular expression to remove all the brackets and tex inside like bellow snippet :

var result = "Basic Cotton Ultra ($20.05)".replace(/ *\([^)]*\) */g, "");
alert(result);
console.log(result)

Upvotes: 2

Related Questions