3 Replies - 962 Views - Last Post: 27 January 2012 - 06:09 AM Rate Topic: -----

#1 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

problem with passing values to javascript function

Posted 27 January 2012 - 05:26 AM

hey i want to send some values from my php code to my client side(javascript)
and i want to send them on the onclick() event in javascript
heres what i have tried so far....
first see my php part
	 echo "<script type='text/javascript'>";
	$numbervar = 0;
	
	
	for($ld = 1; $ld <= $dim; $ld++):

		$calendar.= '<td class="calendar-day">';
			
			$numbervar++;
			$calendar.= '<div class="day-number" div id="demo" onclick="store(<?php echo $numbervar; ?>)">
			'.$list_day.'
		
			
			</div>';
			
echo "</script>";

and heres my javascript function
<script type='text/javascript'>

function store(x)
{
document.write(this.x);
}
</script>
	


according to to what i have written the javascript function should print out the variable but its not.

Is This A Good Question/Topic? 0
  • +

Replies To: problem with passing values to javascript function

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: problem with passing values to javascript function

Posted 27 January 2012 - 05:33 AM

View Postparthmody90, on 27 January 2012 - 01:26 PM, said:

according to to what i have written the javascript function should print out the variable but its not.

you can check in the source code whether PHP printed the value successfully.

other than that, your Javascript function will kill your whole page (including the Javascript code).
Was This Post Helpful? 0
  • +
  • -

#3 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Re: problem with passing values to javascript function

Posted 27 January 2012 - 05:38 AM

no,the php is working fine,only the javascript function is not working...please help as to how can i pass values from the php to the javascript
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: problem with passing values to javascript function

Posted 27 January 2012 - 06:09 AM

if the PHP is "working fine", the value is passed from PHP to Javascript. the problem you have is in Javascript itself.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1