2
Contributors
9
Replies
11
Views
7 Years
Discussion Span
Last Post by javaAddict
0

Use javascript, get the id or the name of the field and set its value to "" empty.

<form name="formName">
<input type="text" name="field" id="field_id" value="aaaaa" />
</form>

Then write code to execute this javascript:

document.formName.field.value="";

//OR

document.getElementById("field_id").value="";

Definitely check this: http://www.w3schools.com/default.asp for more.

0
<SCRIPT language="javascript">

function validate(){
    if (document.getElementById('employerName').value=""){
        alert("Fill in Employer Name");
    }
}

function reset(){
    document.getElementById('employerName').value="";
}
function box(){
    alert("Employer Successfully Save");
    reset();
}
</script>

============================================================
<html:form action="/GetCallEmployerActionPath" onsubmit="box();">
    <table style="margin:50px auto; border:1px solid gray;" border="1">
        <tr>
            <td>Employer:</td>
            <td colspan="2">
                <div id="employerName"><html:text property="employerName"/></div>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="right">
                <input type="submit" value="Save"/>
            </td>
        </tr>
    </table>
</html:form>

Edited by mike_2000_17: Fixed formatting

0

I am not familiar with these tags:
<html:text property="employerName"/>
So I don't think that this will work:
document.getElementById('employerName').value="";
The employerName in the getElementById must be the id attribute of the text field.

Also if you want any of the javascript functions you have declared to be executed, you need to call them like you did with box function. Using events: onxxxxxx (onclick, onsubmit).

For the onsubmit, the function you call must return true or false.

function validate(){
   if (employee is empty) {
      alert("your error message");
      return false;
   }
   return true;
}

......
<html:form action="/GetCallEmployerActionPath" onsubmit="return validate();">
0

<html:text property="employerName"/> ====>> this is jsp code using html taglib
if i change it to <input type="text" id="employerName"> it will create an error on my other java action class..
do i need to input the return in my function??

0

Does this have an id attribute? Can you try to write this:

<html:text property="employerName" id="employerName" />
0

Then use something like this and see if it works:

document.<the name of the form the text field is inside>.employerName.value=""
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.