Susanne92
Susanne92

Reputation: 217

transfer php-variable to javascript variable

I have incorporated this simple datetimepicker : http://trentrichardson.com/examples/timepicker/#rest_examples

So it looks

<?php $tabname = "brightness"; ?>
<script type="text/javascript">
$('#datumstartbrightness').timepicker();
</script>
...
<input type="text" name="datumstart<?php echo $tabname; ?>" 
                id="datumstart<?php echo    $tabname; ?>"/> 
...

With this code it works and datetimepicker appears !

But with this ...

<?php $tabname = "brightness"; ?>
<script type="text/javascript">
$('#datumstart<?php echo $tabname; ?>').timepicker();
</script>
...
<input type="text" name="datumstart<?php echo $tabname; ?>" id="datumstart<?php echo     $tabname; ?>"/> 
...

DateTimePicker doesn't appear. What can be wrong with this line

$('#datumstart').timepicker();

Upvotes: 1

Views: 128

Answers (1)

wildhaber
wildhaber

Reputation: 1661

You need to do the ready-state first before you can call jQuery-Functions: So try this:

<script type="text/javascript">
$(function() {
   $('#datumstart<?php echo $tabname; ?>').timepicker();
});
</script>

Upvotes: 3

Related Questions