SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Nova Scotia, Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Print URL in a input tag

    Hello,

    I have been searching for a JavaScript that will help me with this problem.

    I have a form, with one input to be set to the directory of the current page.

    example:

    Real URL: http://www.site.com/folder/dir/page.html
    What I want printed: http://www.site.com/folder/dir/

    Can anyone give me a script, or point me in the right direction.

    Thanks,
    Jeremy Ross

  2. #2
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is pretty basic, and assumes that you have no / in your querystring.
    Code:
    var a = new String(window.location);
    var b = a.split("/");
    var c = b.pop();
    var d = b.join("/");
    alert(d);
    d has what you need. If you want, put that code in a function (make sure you say return d, then in your input field where you want it to appear, VALUE="javascript:functionName()" . Add READONLY if you don't want the user to be able to change it.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Nova Scotia, Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, I have got the code all working for my site now.

    Thanks,
    Jeremy Ross


Bookmarks

Posting Permissions

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