I have the following Facebook snippet which I'm using to allow my site users to post information to their Facebook wall as part of a classic asp page. It works absolutely perfectly. However I'd like to pass in a variable for use within the script so that the post contains dynamic content, but I can't figure out how to.
My use of document.getElementById('vCarPrice') in the example below isn't working.
Does anyone know what I'm doing wrong?
<div id="fb-root">
</div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '<insert app id here>', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'Car Price News',
link: ' http://www.car.com/',
picture: 'http://www.car.com/logo.jpg',
caption: 'The Price of a saloon is now £' + **document.getElementById('vCarPrice')** + '. Buy Now!',
description: 'The place to be for all the latest car prices.',
message: ''
});
});
});
</script>
Where is this code compared to the rest of the document? And the document.getElementById() is going to return an HTML object... depending on what type of tag the info you want to extract is in, you can do something like document.getElementById('id').innerHTML or .value or something to actually get the text you want, not the entire object