I want to carry out some validation in javascript before posting, so basically I want to:
first problem is I cannot seem to pass the textbox value to the script, is this prevented under struts? second problem is the changing of the back colour of the textbox on error.
<html:text property="date1_1" maxlength="8" value="<%=WeekOne.get(1)%>" size="15" onchange="validateBox(this.value)"/>
<script type="text/javascript">
function validateBox(textBox)
{
alert("here");
var p = textBox.value();
alert(p);
}
</script>
To solve your problems you need to fix some errors in the code. I will show you what to fix trying to achieve what you've written by numbers.
For example
<html:text property="floor" styleClass="input" size="30" tabindex="12" onchange="validateBox(this)"/>
<script type="text/javascript">
var textBoxBackgroundColor;
function validateBox(textBox) {
var p = textBox.value;
if (textBoxBackgroundColor == null)
textBoxBackgroundColor = textBox.style.backgroundColor;
//validate
if (p < 0)
textBox.style.backgroundColor = '#000000';
else
textBox.style.backgroundColor = textBoxBackgroundColor;
}
</script>
will check that textbox floor is positive.