Solved

Remove part of url

Posted on 2013-01-13
2
371 Views
Last Modified: 2013-01-13
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
Comment
Question by:peps03
2 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 300 total points
ID: 38772126
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
 

Author Closing Comment

by:peps03
ID: 38772237
Thanks!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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)

770 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