1

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();

3
  • Have you checked the actual output in your inspector/source? And you're JS is executed after the DOM is loaded right? Commented Jan 17, 2013 at 12:43
  • There is nothing wrong there: $('#datumstart<?php echo $tabname; ?>').timepicker(); Commented Jan 17, 2013 at 12:46
  • I noticed something else. datumstart and brightness are Dutch and English. You are using id's and classes with mixed up languages. It's not a big deal, but it's nice to have it all in English. Makes it more uniform and makes stuff a bit more descriptive/obvious for other programmers who don't speak the native language :) Commented Jan 17, 2013 at 21:35

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

2 Comments

I agree with the point that we need do the ready-state first. However, the echo will not output the space in the PHP code except this space is a string constant.
@Susanne92 you're welcome. You can thanking by "accepting" the answer. Simply click on the tick on the left.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.