Free All Ebook PDF Download - Expekt bonuses - Debt Consolidation - Anime Downloads - Submit articles

PDA

View Full Version : what js event?


promotingspace.net
Sep 3rd 2008, 6:05 am
Hi
I have a form ( with 4 fields for numbers) and want a javascript function to divide the field input by 100 when we go to next field
first i need to know what event should be used
the function should be simple but i don't know how to set the argument
like:
function devideby100(number){
var obj
obj = document.getElementById('myfield')
obj.value='number/100'
}

then my fields will be:
<input type="text" value="" OnEvent='divideby100();'

But I'm sure it won't work. this is my first function in javascript. Please let me know the correct code
Thanks in advance

scriptdance
Sep 3rd 2008, 6:09 am
I think you should use onBlur="divideby100();".

Autodidact
Sep 5th 2008, 9:04 pm
If I understand your request this is what you need

function divideby100(obj) {
var input = obj.value;
if (input.length > 0 && !isNaN(input)) {
obj.value = input/100;
} else {
obj.value = '';
}
}
<input type="text" onblur="divideby100(this)" />

This protects you when the user types in something other than a number