Gaurav_0093 Gaurav_0093 - 1 year ago 61
jQuery Question

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.

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download