0

OK , This is my Html code :

<span id="d"></span>

And this is my Java Script code :

<script>document.getElementById('d').innerHTML = (date.format('DD'));</script>

Now span have a value , I want to get this value from Span and put it into variable then insert it into Database but i don't know how to get value from span .

Sattar
  • 108
  • 4
  • 12

3 Answers3

0

but i don't know how to get value from span .

Just use the same property, you used to set the so called "value" to get it as well.

var value = document.getElementById('d').innerHTML;

After doing the above you'll be able to send it to your backend with ajax.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0

This way you will get value

var value = document.getElementById('d').innerHTML;

Use Jquery Ajax to post the value from id then save it in database

$.ajax({
   url : pathofyoursavingphpscript.php
   data : {divVal:value} 
   success:function(data){
      alert('value is saved in database');
   }
})
justrohu
  • 595
  • 3
  • 9
0

You can use this to get the value and add it to a php variable

$v = "<script> document.write(document.getElementById('d').innerHTML) </script>";
Javier
  • 103
  • 11