newbie: How to get Page ID?

D

deko

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.
 
B

Benjamin

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).
 
D

deko

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!
 
D

deko

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top