Hi, am a beginner in JS (not my preferred language) but just want to accomplish something simple (Im guessing simple)
I have a form that has a text box that needs to be filled with a "time". The time is gotten by a list of text links that when clicked, will fill that text box with that time.
sample below:
Code:
<script language="javascript">
<!--
function writeTimeTag(code)
{
var cache = document.time.shout.value;
this.code = code;
document.time.shout.value = cache + code ;
document.time.shout.focus();
}
//-->
</script>
<form name="time" method="post">
<input type="text" name="shout" size="8" maxlength="8">
<a name="smilies"></a> <a href="#times" onClick="writeTimeTag('09:00:00')" >9:00</a>
<a href="#times" onClick="writeTimeTag('09:30:00')" >9:30</a>
<a href="#times" onClick="writeTimeTag('10:00:00')" >10:00</a>
<a href="#times" onClick="writeTimeTag('10:30:00')" >10:30</a>
<a href="#times" onClick="writeTimeTag('11:00:00')" >11:00</a>
<a href="#times" onClick="writeTimeTag('11:30:00')" >11:30</a> <br>
</form>
So, my question is:
When someone clicks on the link, how can I prevent them from adding more 'times' to the text box. As it is now, if they click on 9:00 it'll put in the box 09:00:00 (good) but if they accidentally also, hit 9:30, it will also be added to the text box (ie 09:00:0009:30:00 ). I put a maxlength of 8 characters, but it ignores that attribute. How can I get it to "clear" the field and then write the time if they chose wrong?