evergrean100
Technical User
I would like to create a JavaScript to clear any blank tab space entries made on a form submit.
If someone enters tabs or blank spaces in the form inputs then clear it out with JavaScript.
My attempt below is not clearing the tabs or blank spaces and doesnt seem to call my function.
Please advise.
If someone enters tabs or blank spaces in the form inputs then clear it out with JavaScript.
My attempt below is not clearing the tabs or blank spaces and doesnt seem to call my function.
Please advise.
Code:
<script>
function eliminateSpace()
{
if(fieldOne == "" || fieldTwo == "" || fieldThree == "")
{
return fieldOne.replace(/^\s+|\s+$/g, '');
return fieldTwo.replace(/^\s+|\s+$/g, '');
return fieldThree.replace(/^\s+|\s+$/g, '');
}
}
</script>
....
<form method="get" name="myform" action="thepage.jsp" onsubmit="eliminateSpace()">
<input type="text" name="fieldOne">
<input type="text" name="fieldTwo">
<input type="text" name="fieldThree">
<input type="submit" name="submit">
</form>