I am a pure beginner of Javascript. I got some advanced experience with php but until now I refused to work with JS.
So now I have a question. I wanted to make possible to pickup date-value from a php-generated calendar and put it into a form input field just below of the same page / script.
My idea was to create an onlick-event for each date data. So in my calendar I have this:
$date = date('Y-m-d',$daystamp);
$post = '<div class="cal_day"><a href="#" onclick="dateclick($date)">'.$day.'</a></div>';
What I thought to do with Javascript is the following:
function dateclick(var x)
{
document.getElementById("date_entry").innerHTML = var x;
}
And my html-input field where I like to have the choosen date-values:
<input type="text" id="date_entry" name="abs_date" size="15" max-length="15"/>
I am sure the solution is simple. At W3Schools I saw that the output of JS doesn't require a return all the time? Should I add it?
Thank you for any answer or help.
UPDATE: So I tried what you mentionned as solution/s: - I removed the "var" before the x. - I have encapsed the $date.
It is still not working. When I look up the element with OPERA it tells me it is a event handler but source file missing. But I have included the functions.js and another function in the same file is working well. I tried the same thing in the try-field on W3Schools and it worket there.. So I guess that there is something in my structure around it that isn't working.
The calendar source line is included above the form element. Is this a problem?
I don't know if I zapped something.
GOT IT The problem was that I needet to put the value into an input element.
The following code works:
function dateclick(x)
{
document.getElementById('date_entry').value=x;
return false;
}
Thanks for all your help!
's around$datein theonclick. But since you are within a'-enclosed string, you'll need to escape them:$post = '<div class="cal_day"><a href="#" onclick="dateclick(\'$date\')">'.$day.'</a></div>';varin your assignment:document.getElementById("date_entry").innerHTML = x;