newbie: How to get Page ID?

Discussion in 'Javascript' started by deko, Aug 24, 2006.

  1. deko

    deko Guest

    I'm trying to retrieve the Page ID of a blog entry with JavaScript so I can
    insert a form while editing the post. So I will need to concatenate the Page ID
    with some HTML and insert it into the post window.

    The page is loaded in my browser, and I can see the ID in the URL in the
    browser's address window (e.g. http ... post.php?post=23), but I don't know
    where to get the ID form. Is it available somewhere in the DOM? How do I
    retrieve it? Should I just grab the variable out of the URL?

    Thanks in advance.
    deko, Aug 24, 2006
    #1
    1. Advertising

  2. deko

    Benjamin Guest

    Good question! Put this in your form and the data will be sent with it.
    <script type="text/javascript">
    var id = location.search.split("=");
    document.write("<input type='hidden' name='postId' value='" + id[1] +
    "' />");
    </script>
    This will work when you are only sending on piece of data.
    post?id=123&foo=bar won't work very well (you won't get the value of
    foo).
    deko wrote:
    > I'm trying to retrieve the Page ID of a blog entry with JavaScript so I can
    > insert a form while editing the post. So I will need to concatenate the Page ID
    > with some HTML and insert it into the post window.
    >
    > The page is loaded in my browser, and I can see the ID in the URL in the
    > browser's address window (e.g. http ... post.php?post=23), but I don't know
    > where to get the ID form. Is it available somewhere in the DOM? How do I
    > retrieve it? Should I just grab the variable out of the URL?
    >
    > Thanks in advance.
    Benjamin, Aug 24, 2006
    #2
    1. Advertising

  3. deko

    deko Guest

    Hi and thanks for the reply.

    Here's what I've got so far (pseudo code):

    [file = quicktags.js]

    (Note: the URL looks like this: http :// ... /post.php?action=edit&post=21)

    var id = location.search.split("post=");

    edButtons[edButtons.length] =
    new edButton('ed_more'
    ,'more'
    ,'<!--more--><form name="bgcolor"
    action="http:// www. example.com/?p= +id[1]#more- +id[1]"
    method="post"><select style="..." etc, etc'
    ,''
    ,'t'
    ,-1
    );

    The above code is in a JavaScript file - so I'm not sure if 'document.write' is
    what I should use (?)

    In any case, I'm sure I'm not concatenating that string correctly...

    The 'edButtons' routine is expecting a literal in that argument beginning with
    <!--more-->, so I'm wondering if I can build the string first and then so
    something like this:

    edButtons[edButtons.length] =
    new edButton('ed_more'
    ,'more'
    , strMyForm
    ,''
    ,'t'
    ,-1
    );

    But I'm very green with JS, so I'm not sure if this would break that routine or
    not... never mind how to build the string...

    So I'm still trying to get proof of concept here. Any suggestions welcome!
    deko, Aug 24, 2006
    #3
  4. deko

    deko Guest

    got it...

    var id = location.search.split("post=");
    edButtons[edButtons.length] =
    new edButton('ed_more'
    ,'more'
    ,'<!--more--><form name="bgcolor" action="http: // www. example . com//?p=' +
    id[1] + '#more-' + id[1] + '" method="post"><select ... etc, etc... '
    ,''
    ,'t'
    ,-1
    );

    Thanks for the help!
    deko, Aug 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Miller
    Replies:
    5
    Views:
    9,076
    kaverao
    Sep 17, 2009
  2. Steve Richter

    get url of page that linked to your page

    Steve Richter, Mar 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    444
    Steve Richter
    Mar 30, 2005
  3. Kylin
    Replies:
    1
    Views:
    371
  4. Jozef
    Replies:
    1
    Views:
    423
    Karl Seguin
    May 26, 2005
  5. Arne Schirmacher
    Replies:
    0
    Views:
    493
    Arne Schirmacher
    Feb 16, 2005
Loading...

Share This Page