Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with using getElementById().getValue in FBJS/Facebook !

I am using this code to generate hidden HTML code in Facebook :

echo "<div id=\"y257y\" style=\"display:none;\">".$fdesc."</div>";

And, I am trying to get this element back in JS using the following code

newVal=document.getElementById('y257y').getValue();

But, I am getting an error: Undefined

Can anyone kindly help me out ?

Thanks.

- ahsan

like image 305
Ahsan Avatar asked Aug 15 '26 01:08

Ahsan


1 Answers

Instead of:

newVal = document.getElementById('y257y').getValue();

try using:

newVal = document.getElementById('y257y').innerHTML;

Are you using any JavaScript library, like jQuery or Prototype? If you're using jQuery:

newVal = $('#y257y').html();

Other suggestions:

Use hidden form element:

echo "<input type=hidden id=y257y value=\"$fdesc\">";

and in JavaScript:

newVal = document.getElementById('y257y').value;

Or just output a <script> tag:

echo "<script>newVal = \"$fdesc\";</script>";

and there's no need to find the value in the DOM – it's already in JavaScript.

like image 80
rsp Avatar answered Aug 17 '26 15:08

rsp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!