HOME ➔ SUPPORT ➔ Community ➔ General CourseLab issues ... Use time into javascript
Use time into javascript
  View type:
Hi all,
I tried to insert javascript code in courselab. but it's not working
the code is show the time


any help please ???
[:confused:][:confused:][:mad:]
the main code is

<SCRIPT LANGUAGE="JavaScript">

var timerID = null
var timerRunning = false

function stopclock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}



function showtime()
{
var now = new Date()

var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()

var timeValue = "" + ((hours > 12) ? hours - 12 : hours)

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"


document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}

function startclock()
{
stopclock()
showtime()
}

//-->
</SCRIPT>

<form name="clock" onSubmit="0">
<INPUT TYPE="text" NAME="face" SIZE=11 READONLY VALUE ="....Initializing....">
</form>

<SCRIPT LANGUAGE="JavaScript">
<!--
startclock()
//-->
</SCRIPT>


thanks .
 
Hi all

the main code is
<?PHP
echo "<SCRIPT LANGUAGE="JavaScript">

var timerID = null
var timerRunning = false

function stopclock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}



function showtime()
{
var now = new Date()

var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()

var timeValue = " " + ((hours > 12) ? hours - 12 : hours)

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"


document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}



function startclock()
{
stopclock()
showtime()
}


//-->
</SCRIPT>


<form name="clock" onSubmit="0">
<INPUT TYPE="text" NAME="face" SIZE=11 READONLY VALUE ="....Initializing....">
</form>

<SCRIPT LANGUAGE="JavaScript">
<!--
startclock()
//-->
</SCRIPT> ";
?>
 
 
LOL It's frustrating isn't it!! These text boxes are html so when you add a code tag like or segment of code it can disappear. like this one <i> ?? oops it's gone </i>
It is quite possible that a timer will or a script to show the time will use a loop somewhere. Courselab likes the code to be indented or it doesn't work. For example

do some functional code
until you get to a certain value


 
 
 
I added a set of html tags for italics that the page interpreted as <i> italics </i>
The same happens with any other kind of functional code, the page tries to use it
 
 
 
 
It seems to me you try to type
&lt;?php
echo &quot;initialising&quot;;
?&gt;
If that is the case: this is not (client side) javascript but (server side) php which will not function within a CL course.

~~~ I hope I am using the right codes. If not, I'll post again [;)] ~~~~
 
 
 
 
 
The code which is below in html file
and I want to modiffy it to javascript inter courselab - But how .

/*
var timerID = null
var timerRunning = false

function stopclock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}



function showtime()
{
var now = new Date()

var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()

var timeValue = " " + ((hours > 12) ? hours - 12 : hours)

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"


document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}



function startclock()
{
stopclock()
showtime()
}



form name="clock" onSubmit="0"
INPUT TYPE="text" NAME="face" SIZE=11 READONLY VALUE ="....Initializing...."
/form


startclock()

*/
Thank you barend and Nick James[:rolleyes:]
 
 
 
 
 
 
ehhh ... after adding ths action with text 'TEST MY TIME' run it as a test and debug is necessary.
Then continue adding the timer
[;)]
 
 
 
 
 
 
 
Thanks my friend ....[:p]
you gave me the Beginning of the road
Really thank you[;)][;)]
 
 
 
 
 
 
 
 
You're welcome [:)]
 
 
 
 
 
 
Make a textbox, give it a id 'timebox'
The open the text editor and open the html view ('Edit HTML'). You'll see a span with the text properties.
Inside this span make a new span:
&lt;SPAN id=time&gt;TIME&lt;/SPAN&gt;

On the textbox make an action 'afterdisplay':
time.innerHTML = "TEST MY TIME";

Next step is to remove this action and add your javascript. Change 'document.clock.face.value = timeValue' to
time.innerHTML = timeValue

The timer is displayed but the next second it generates an error. I didn't look if his was caused by an error in javascript or CL.
[:cool:]
 
Hi all

the main code is
<?PHP
echo "<SCRIPT LANGUAGE="JavaScript">

var timerID = null
var timerRunning = false

function stopclock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}



function showtime()
{
var now = new Date()

var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()

var timeValue = " " + ((hours > 12) ? hours - 12 : hours)

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"


document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}



function startclock()
{
stopclock()
showtime()
}


//-->
</SCRIPT>


<form name="clock" onSubmit="0">
<INPUT TYPE="text" NAME="face" SIZE=11 READONLY VALUE ="....Initializing....">
</form>

<SCRIPT LANGUAGE="JavaScript">
<!--
startclock()
//-->
</SCRIPT> ";
?>
 
Hi all
I tried to insert javascript code in courselab. but it's not working
the code is show the time


any help please ???

the main code is

<<SCRIPT LANGUAGE="JavaScript">

var timerID = null
var timerRunning = false

function stopclock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}



function showtime()
{
var now = new Date()

var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()

var timeValue = "" + ((hours > 12) ? hours - 12 : hours)

timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"


document.clock.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}

function startclock()
{
stopclock()
showtime()
}

//----->
</SCRIPT--->

<<form name="clock" onSubmit="0">
<INPUT TYPE="text" NAME="face" SIZE=11 READONLY VALUE ="....Initializing....">
</form>

<<<SCRIPT LANGUAGE="JavaScript">
<!--
startclock()
//-->
<<</SCRIPT>


thanks .
Subject:
Message options
No additional options