PHP Javascript Problem.

4 views
Skip to first unread message

Vishwanath Sarang

unread,
Aug 26, 2012, 11:40:21 AM8/26/12
to dbit-t...@googlegroups.com
So I have been facing this problem lately and I couldn't find a solution on Stack Overflow. I kind am not sure how to frame the question too. So I have a JS function which I am calling from a PHP page onclick and passing a date parameter to it. 

<input type="image" src="images/addlog.png" style="width:14px;" onclick="return popuplog('."$mynewdate1".');">

On execution, the source code is 

<input type="image" src="images/addlog.png" style="width:14px;" onclick="return popuplog(2012-08-19);"> 

Now the problem is this. Say the function is like 

function popuplog(str) 
{
alert(str);
}

Its displaying me a alert message with 1985 which is actually 2012 minus 08 minus 19! :P

I am not sure now how to fix this. I tried putting all sorts of quotes around the $mynewdate1 variable! Didn't work as much!

Rahul Isola

unread,
Aug 26, 2012, 11:47:42 AM8/26/12
to dbit-t...@googlegroups.com

Quotes are not correct. If u can send me d complete PHP line with <input type="image" src="images/addlog.png" style="width:14px;" onclick="return popuplog('."$mynewdate1".');"> I can tell u which 1s to put where.

Rahul

> --
> Email to group : dbit-t...@googlegroups.com
> To unsubscribe, send email to
> dbit-techtal...@googlegroups.com
> Visit this group at
> http://groups.google.com/group/dbit-techtalk?hl=en

Vishwanath Sarang

unread,
Aug 26, 2012, 12:41:27 PM8/26/12
to dbit-t...@googlegroups.com

Arey the quotes are correct! This is the exact line!


echo '<td style="background-color:#f4f4f4;"><input type="image" src="images/addlog.png" style="width:14px;" onclick="return popuplog('."$mynewdate1".');"></td>';
 

peter dmello

unread,
Aug 26, 2012, 2:06:29 PM8/26/12
to dbit-t...@googlegroups.com
I don't know PHP, but based on what you expect, you need to pass it a date object instead of a date string (or as is being passed an expression which is giving you the subtracted value when the quotes are not put).
something like return popuplog(new Date('2012-08-19'))

<html>
<head>
<script type="text/javascript">
function hello(date){
 alert('hello '+date)
 }
</script>
</head>
<body>
<input type="button" onclick="hello(new Date('2012-08-26'))"/>
</body>
</html>

Good to see a post on techtalk after ages :)
On Sun, Aug 26, 2012 at 12:41 PM, Vishwanath Sarang <vishf...@gmail.com> wrote:

Arey the quotes are correct! This is the exact line!


echo '<td style="background-color:#f4f4f4;"><input type="image" src="images/addlog.png" style="width:14px;" onclick="return popuplog('."$mynewdate1".');"></td>';
 

--

Vishwanath Sarang

unread,
Aug 26, 2012, 2:22:19 PM8/26/12
to dbit-t...@googlegroups.com
Hey Peter,

Thanks, that worked. Actually initially it displayed 1 Jan 1970 everytime, and the source code seemed pretty fine. So then I just dropped the new worked and used 

return popuplog(Date($mynewdate1)) instead. It worked. It alerts with the entire date time. Rest I cant get done.

Thank you very much.

:-)
Reply all
Reply to author
Forward
0 new messages