Adding javascript to a formfield

D

DirkG

Hi,

I've been trying to add the results of the javascript (listed below) to a
single formfield.
The result of the javascript calculation has to be dumped into a comma
seperated file. Unfortunately I've been unable to add the javascript to the
formfield. What should I do?

<html>
<body>

<script type="text/javascript">

var d = new Date()
document.write(d.getHours())
document.write(":")
document.write(d.getMinutes())

</script>

</body>
</html>

Thanks in advance
Dirk
 
D

David Berry

You need to give your script a function so that it can be called from an
event, such as OnLoad, onClick etc. Ex:

<script type="text/javascript">
function myFunction(){
var d = new Date()
document.write(d.getHours())
document.write(":")
document.write(d.getMinutes())
}
</script>

The you can either add it to the form, ex:

<form name=submitform onSubmit="return myFunction()">

or a field, ex:

<input type = "text" onFocus="myFunction();">

You may need to pass parameters to the function and you'll need to decided
what event triggers it (OnFocus, OnBlur, OnKeypress etc ... )

See http://javascript.internet.com for sample scripts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top