Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP & Javascript - Datepicker issue

Status
Not open for further replies.

zinja

MIS
Nov 14, 2002
149
US
I am trying to use the datepicker javascript from nfstools.com/tips/DatePickerTest.htm I have a php function (userform) that controls the output of the form fields and I also have a javascript function (displayDatePicker) that is part of the same php file. The javascript works if I have it separate from the php function like this:

Code:
<form>
Expiration Date: <input name="date_expired"> 
<input type=button value="select" onclick="displayDatePicker('date_expired', this);">
</form>

But when I try to interlace my php function with it, I can't seem to get the syntax and the quotes correct. This does not work:

Code:
   echo userform ($lang['Date_Expired'], "<input name='date_expired'><input type=button value='select' onclick='displayDatePicker('date_expired', this);'>");

Any ideas?

LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
You're doing to have to diffentiate strings better in that parameter you pass to the function.

echo userform ($lang['Date_Expired'], '<input name="date_expired"><input type=button value="select" onclick="displayDatePicker('date_expired', this);">');


Want the best answers? Ask the best questions! TANSTAAFL!
 
sleipnir214,

Thanks for the assistance. I also got a response back from the developer. He indicated that I should modify the line as follows:

Code:
echo userform ($lang['Date_Expired'], '<input name="date_expired"><input type=button value="select" onclick="displayDatePicker(\"date_expired\", this);">');

I don't get an error, but the datepicker does not popup the calendar. I realize this is not a typical php issue, but any help would be appreciated. I have tried alot of different ways to use quotes and separate the strings, but most efforts wind up getting a parse error.


LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
I don't know. I'm unfamiliar with the JavaScript class that this HTML will invoke.

One thing that you should probably do is change:

<input name="date_expired">

for

<input type="text" name="date_expired">


What does your function output? What's printed by the echo statement?


Want the best answers? Ask the best questions! TANSTAAFL!
 
Assuming that this involves the displayDatePicker library published by Julian Robichaux at [ignore][/ignore], and his javascript and example CSS are in the external files test_foo.js and test_foo.css, respectively, then this code:

Code:
<?php
function test_function ($somestring)
{
        return $somestring;
}

print '<html>
        <head>
                <script src="test_foo.js"></script>
                <link href="test_foo.css" rel="stylesheet" type="text/css">
        </head>
        <body>';
print '
                <form method="post" action="show_post.php">';


$a = <<< EOV
                        <input type="text" name="date_expired"><input type=button value="select" onclick="displayDatePicker('date_expired');">
EOV;

echo test_function($a);


print '<br>
                        <input type="submit">
                </form>
        </body>
</html>';
?>

Works for me.

Don't make yourself crazy trying to get all the internal quotes escaped and double-escaped to output JavaScript code. Use the heredoc syntax to assign the string to a variable then use that variable with your function


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top