• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

Remove part of url

Hi,

I'm trying to remove the last part of an url, when a dropdown is changed, that looks like this:
edit.php?do=delete&id=x
The "X" needs to be replaced.

The code is use is:
$('#delemail').attr('href', function(index, attr) {
	var url1 = attr;
	url = url1.substring(0, url1.length - 1);
	return url + foo;
});

Open in new window


But this only removes the 'X'. So the first time it works fine, but if the "X" is replaced with an id, like 233, and the dropdown is changed again, the id will be: 23XXX

How do i completely replace the whole id onchange? (no matter how long the id is)

Thanks
0
peps03
Asked:
peps03
1 Solution
 
rrzCommented:
If  id is always the last param, then you could use the String method    lastIndexOf().
url = url1.substring(0, url1.lastIndexOf("=") + 1);

Open in new window

0
 
peps03Author Commented:
Thanks!!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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