Jump to content

Remove characters from a string starting at a specific character


raymond_feliciano

Recommended Posts

I have a form with some dropdownlist that get populated dynamically(depends on what the user chooses) with jquery and an xml file. In the form I have a button that takes the info and populates another form with the values of the ddl. I have coded script which populates the second form with jquery and the name of each input get dynamically added like so:

 

<input type="text" value="'+model+'" name="Model_'+model+'" id="'+model+'" readonly size="'+model.length+'" />
<input type="text" value="'+model+'" name="Model'+model+'" id="'+model+'" readonly size="'+model.length+'" />>
<input type="text" value="'+color+'" name="Color'+color+'" id="'+color+'" readonly size="'+color.length+'" />
<input type="text" value="'+part+'" name="Part'+part+'" id="'+part+'" readonly size="'+part.length+'" />
<input type="text" value="$'+price+'" name="Price'+price+'" id="'+price+'" readonly size="'+price.length+'" />
<input type="text" value="'+qty+'" name="Quantity'+qty+'" id="'+qty+'" readonly size="'+qty.length+'" />
<input type="text" value="'+total+'" name="Total'+total+'" id="'+total+'" readonly size="'+total.length+'" />

 

What I want to do is grab the name of the element and remove the underscore and everything else form rileft to right so I am left with just the word before the underscore. I tried using substr($key,0,-28) but that wont work since everything after the underscore will have a different length. I was wondering if there is a way i can keep everything before the underscore and remove the underscore and everything after that.

Thanks in advance for any input I get.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.