Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    textbox remove data upto 2nd to last /

    if i have a textbox with the contents http://www.blah.com/b/n/g/g/gg/h/d/
    how usnig javascript can i make it when a button is pressed change to:
    http://www.blah.com/b/n/g/g/gg/h/
    and then when the button is pressed again it changes to:
    http://www.blah.com/b/n/g/g/gg/

    thanks in advance

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function parentDirectory(remdir) {
    	remdir = remdir.substring(0,remdir.lastIndexOf("/")-1);
    	remdir = remdir.substring(0,remdir.lastIndexOf("/")+1);
    	return remdir;
    }

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how would i call the function from a button?

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    <html>
    <head>
    <title>untitled</title>
    </head>
    <body>
    <form>
    <input type="text" name="path" size="36" value="http://www.blah.com/b/n/g/g/gg/h/d/">
    <input type="button" value="One Less Dir"
    onclick="path.value=path.value.replace(/\w+\/$/, '')">
    <input type="reset">
    </form>
    </body>
    </html>

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you so much i know understand.
    when its explained i can learn and not just copy and paste.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •