Validating forms in jsp using javaScript

Hi all i'm trying to validate this form with javeScript. i was testing it with just the <input type=text name= file> first. it works but after the alert message it still posts to writeXML......
i tried putting the fuction valid() after the <form> tag but it still posts it to writeXML.jsp.......can anyone help me please........What i want to do is make sure that something is typed in all the forms befor posting to writeXML..Thanx
<html>
<head> <title>Create MultipleChoice Questions</title> </head>
<script language="JavaScript">
function valid(form) {
     if(form.file.value == "")
     alert("Please enter the file name")
</script>
<body bgcolor="#cccccc">
<% int count = 0;
String number = request.getParameter("nOfq");
int qNumber = Integer.parseInt(number); %>
<form action="writeXML.jsp" method="POST">
<center>
     <table bgcolor="silver" border="1" width="75%">
     <tr align="center"><td><b>Type in the Name of your Questionnaire here eg. BlackHistory.      Dont leave any spaces between letters</b><br>
     <textarea name="file" rows="1" cols="25"></textarea><br>
     </td></tr>
<% for(int i=1;i<qNumber+1; i++) { %>
<%count++;%>
     <tr align="center" bgcolor="#336699"><td><b>QUESTION <%= count %>: </b><br>
     </td></tr>
     <tr align="center"><td><b>ENTER QUESTION:</b><br>
     <textarea name=<%="questionText"+i%> rows="5" cols="65"></textarea><br>
     </td></tr>
     <tr align="center"><td><b>CHOICE 1:</b><br>
     <textarea name=<%="choice_1"+i%> rows="2" cols="50"></textarea><br>
     </td></tr>
     <tr align="center"><td><b>CHOICE 2:</b><br>
     <textarea name=<%="choice_2"+i%> rows="2" cols="50"></textarea><br>
     </td></tr>
     <tr align="center"><td><b>CHOICE 3:</b><br>
     <textarea name=<%="choice_3"+i%> rows="2" cols="50"></textarea><br>
     </td></tr>
     <tr align="center"><td><b>CHOICE 4:</b><br>
     <textarea name=<%="choice_4"+i%> rows="2" cols="50"></textarea><br><br><br>
     </td></tr>
     <tr align="center" bgcolor="#679995"><td><b>CORRECT ANSWER:</b><br>
     <textarea name=<%="cAnswer"+i%> rows="2" cols="50"></textarea><br><br><br>
     </td></tr>
<% } %>
<tr>
<td align="center"><input type="submit" name="next" value="NEXTT" onClick="valid(this.form)">
<td align="center"><input type="hidden" name="qCount" value="<%=count+1%>">
</td></tr>
</table>
</center>
</form>
</body>
</html>

this Corrected code works perfectly
<html>
<head> <title>Create MultipleChoice Questions</title> </head>
<script language="JavaScript">
function valid(form) {
if(form.file.value == ""){
alert("Please enter the file name");
frmValid.file.focus();     
}else{
     frmValid.action="writeXML.jsp";
     frmValid.submit();
</script>
<body bgcolor="#cccccc">
<% int count = 0;
int qNumber=-1;
String number = clearNull(request.getParameter("nOfq"));
if(! number.equals(""))
qNumber = Integer.parseInt(number);
%>
<form name="frmValid" method="POST" >
<center>
<table bgcolor="silver" border="1" width="75%">
<tr align="center"><td><b>Type in the Name of your Questionnaire here eg. BlackHistory. Dont leave any spaces between letters</b><br>
<textarea name="file" rows="1" cols="25"></textarea><br>
</td></tr>
<% for(int i=1;i<qNumber+1; i++) { %>
<%count++;%>
<tr align="center" bgcolor="#336699"><td><b>QUESTION <%= count %>: </b><br>
</td></tr>
<tr align="center"><td><b>ENTER QUESTION:</b><br>
<textarea name=<%="questionText"+i%> rows="5" cols="65"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 1:</b><br>
<textarea name=<%="choice_1"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 2:</b><br>
<textarea name=<%="choice_2"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 3:</b><br>
<textarea name=<%="choice_3"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 4:</b><br>
<textarea name=<%="choice_4"+i%> rows="2" cols="50"></textarea><br><br><br>
</td></tr>
<tr align="center" bgcolor="#679995"><td><b>CORRECT ANSWER:</b><br>
<textarea name=<%="cAnswer"+i%> rows="2" cols="50"></textarea><br><br><br>
</td></tr>
<% } %>
<tr>
<td align="center"><input type="submit" name="next" value="NEXTT" onClick="valid(this.form)">
<td align="center"><input type="hidden" name="qCount" value="<%=count+1%>">
</td></tr>
</table>
</center>
</form>
</body>
</html>
<%!
private String clearNull( String sField ) {
return ( sField == null ) ? "" : sField;
%>

Similar Messages

  • How to do  validation in jsp using javascript

    how to do validation in jsp using javascript

    The same way you do with any HTML page.
    Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required.
    However this is javascript validation only - javascript can never call JSP code.

  • How to set JavaBean in JSP using JavaScript function

    Hello,
    When a user clicks on an item, I want to execute a JavaScript function. Within that function, I want to set specific JavaBeans (<jsp:setProperty... />) within my JSP page.
    Can anyone tell me how to do this or where I can find examples on how to set JavaBeans in a JSP page using JavaScript?
    Thanks.
    Pat

    try this:
    your.jsp
    <html>
    <SCRIPT>function buttonClick()
    {document.compform.submit();}
    </SCRIPT>
    <body>
    <form name=compform method=post action='your.jsp'>
    <%
    //write your code which you want to execute once the button is submitted
    String submit;
    submit=request.getParameter("mysubmit");
    if ((submit != null) && (! submit.equals("")))
    %>
    <input type=hidden name=mysubmit value="submit">
    <input type=button value=add onclick='buttonClick()'>
    </form></body></html>

  • How to set a form element value using javascript?

    Hello,
    I have been using the following two functions in AS 9.0.2 to set form values in javascript and it works correctly. However, the same code does not work in AS 10.1.2.0.2. Would appreciate if someone could let me know how to set form elements using Javascript(onchange of a field).
    function set_item_value(p_field_name, p_value)
    var v_index, v_full_name;
    for(v_index=0; v_index<document.forms[0].length; v_index++)
    v_full_name = document.forms[0].elements[v_index].name.split
    if (v_full_name[2] == p_field_name)
    document.forms[0].elements[v_index].value = p_value;
    function get_item_value(p_field_name)
    var v_index, v_full_name, v_return="";
    for(v_index=0; v_index<document.forms[0].length; v_index++)
    v_full_name = document.forms[0].elements[v_index].name.split
    if(v_full_name[2] == p_field_name)
    if(document.forms[0].elements[v_index].type != "radio")
    v_return = document.forms[0].elements[v_index].value;
    else
    if(document.forms[0].elements[v_index].checked)
    v_return = document.forms[0].elements[v_index].value;
    if(v_return == " ")
    v_return = "";
    return v_return;
    Thanks
    Dev

    This is not the best way to write JavaScript in Portal environment!
    You can't be sure that a form is the first in the html source!
    In Portal you change the order of your portlets, and also you can have several instances of the same portlet on the same page!!!
    You should use qualified form and field names!
    Please check the following JPDK methods:
    UrlUtils.htmlFormName
    HttpPortletRendererUtil.portletParameter

  • List of forms features that use JavaScript

    I want to distribute a fillable form that doesn't use any JavaScript. Is there a list of features/toools that use JavaScript so I can avoid them? I'm on Acrobat Pro 9.2 in Windows XP SP3.
    Regards,
    Glenn

    Bernd, I don't think it is that simple. I don't know any JavaScript commands. I included a field in a form that summed two other fields, really simple stuff. If I disable JavaScript in Acrobat, I get a warning that this form uses JavaScript.
    So, I removed the field that totals and still get a warning. I'm guessing it is due to some other element such as radio buttons and/or mutually exclusive check boxes that use JavaScript without me knowing about it.
    So my questions is "Is there a list of form-creation tools that use JavaScript? Are there any check boxes, radio boxes or any other standard form creating tools that use JavaScript?"
    Thanks for the reply,
    Glenn

  • Communication between two Jsps using Javascript

    I m new to use Javascript.
    I will really aprreciate if someone take some time and clarify my doubt.
    Here is the situation
    There is a 'Browse' hyperlink on the Parent.jsp. As soon as, i click the link, a new jsp Child.jsp is opening with the values coming from the backend. As the user selects some values in the Child jsp and say 'Add', the values should be transfered and displayed ( can be done by creating dyanamic 'divs')to the Parent jsp. Here is the tricky one. The Parent.jsp should not refreshed.
    I tried so hard to achive this, but failed miserably.
    (Creation of dynamic divs is just a way to achive this)
    Can you please help me out in this? Is there any other way, this requirement can be achived?
    Advance thanks

    Hope this would help
    http://digital.ni.com/public.nsf/allkb/B937AC4D8664E37886257206000551CB
    Parallel port acess VIs will be in found in the following path.
    C:\Program Files\National Instruments\LabVIEW xxxx\examples\portaccess\parallel port examples.llb
    However,the above VIs doesn't support Windows Vista & Later.

  • Validating the htmlb inputfield using javascript

    Hi,
    I am trying to validate the htmlb inputfiels using the javascript,i want to get the value entered iin this inputfield in the javascript in order to validate
    plz help me on how do i get the value of the inputfield in the script.
    Thanks
    Ajay

    Hi
       please check the below example if it helps you
    <script language='JavaScript'>     
          function validateInputField() {
              var funcName = htmlb_formid+"_getHtmlbElementId";
              func = window[funcName];
              var inputfield = eval(func("xyzinputfield"));
              var inputFieldValue = inputfield.getValue();
              input  =  inputFieldValue.toLowerCase();
              if ( input.checkforsomecondition ) {
                           true perform some action
                else {  false display some message
                        alert( "please......... give some message upon failure " ); }
    </script>
    use some hbj code similar to this
    <tr><td width = 40%>
    <hbj:inputField
               id="xyzinputfield"
               type="string"
               maxlength="100"
               value="Your name here"
               jsObjectNeeded="true"
    />
    <hbj:button
               id="exbutton"                 
               value="Your name here"
               OnClientclick="validateInputField()"
    />
    regards
    jagdesh
    Message was edited by: jagdeshwar Manipatruni

  • Making PL/SQL calls in an HTML form that also uses Javascript

    Hi -- I'm completely new to Web Development and am trying to create an HTML page which contains Javascript for the event handlers. However, I need to dynamically populate one of my combo boxes based on the change event of another combo box, and need to call a stored procedure to write the options for the dynamically loaded box. I also need to figure out how to write my data to the database, etc., so I figured that once I determine how to make my PL/SQL calls for this one event, I should be good to go with the others.
    Any help is greatly appreciated!
    ~Christine

    Hi!
    You have several options:
    -mod_plsql and Web Toolkit Reference
    http://download-uk.oracle.com/docs/cd/B14099_14/web.1012/b14010/toc.htm
    http://download-uk.oracle.com/docs/cd/B14099_14/web.1012/b15896/toc.htm
    -JDBC from Java
    http://download-uk.oracle.com/docs/cd/B19306_01/java.102/b14355/basic.htm#sthref160
    -portlet
    http://www.oracle.com/technology/products/ias/portal/pdk.html
    I think first you should read about this technologies to get better overview and then you can decide which is the best for you!

  • Using JavaScript to Determine a Form's Folder Name

    We have an awful lot of forms, and in many cases, our custom JavaScript applies to all forms in a given folder. We would like to determine the form's folder name so that we don't have to list each and every form in a giant "IF" statement.
    Has anyone figured out how to determine a form's folder using JavaScript?
    Thanks!
    - Jake

    Jake_Turrell wrote:
    I think the only solution to the "refresh" issue would be to somehow query the hsp_object table and grab the parent_id (which for a form is the folder ID). If anyone figures out how to query the application repository from JavaScript,that would be very, very cool.
    As the database is server side and javascript is client side you would have to use something like an ajax call that passes the form id into an jsp script, the jsp script would query the repository and return the value to javascript.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Using Javascript with SOFIAFramework

    Hi everyone,
    I'm trying to set one login page designed in JSP, making use of the SOFIA framework. In order to make some validations, i have to use Javascript at the client side itself.
    I tried by calling a function(Javascript) on the click of a button. My making use of alert(), i realized that i reached the function. But i got errorwhen i tried to retrieve the value of one text field.
    CODE : (Javascript)
    function check(){
    alert("Inside function");
    var name=newForm.username.value;
    alert(name);
    I got error at the second line of code inside the function and it states that, "newForm.username.value is null or not an object"
    Could anyone help ,me to get out of this.

    It might even be possible to use Reader XI for filling in the forms and saving the forms. Since this is a free product, then cost would not be an issue. The issues will be the custom files that would need to be installed on each user's system.

  • Problem with populating a radiogroup using javascript

    I have a rediogroup in a form and am using javascript and process to fill the value of that radiogroup. However, i always got error message with the javascript. Could somebody help me check what is wrong. here is the scrpits:
    if(l_Opt_Xml1.firstChild) {
    if l_Opt_Xml1.firstChild.nodeValue == 'F'
    html_GetElement('P59_SEX')[0].checked = true;
    if l_Opt_Xml1.firstChild.nodeValue == 'M'
    html_GetElement('P59_SEX')[1].checked = true;
    Thanks.
    Jen

    I have a rediogroup in a form and am using javascript and process to fill the value of that radiogroup. However, i always got error message with the javascript. Could somebody help me check what is wrong. here is the scrpits:
    if(l_Opt_Xml1.firstChild) {
    if l_Opt_Xml1.firstChild.nodeValue == 'F'
    html_GetElement('P59_SEX')[0].checked = true;
    if l_Opt_Xml1.firstChild.nodeValue == 'M'
    html_GetElement('P59_SEX')[1].checked = true;
    Thanks.
    Jen

  • Retrieving form components added via javascript

    I looked around and couldn't find anything on this. I'm adding form elements dynamically using Javascript. How do I read those dynamically added elements? Faces doesn't pick them up and they're not coming through in the request attributes (HttpServletRequest#getAttribute(String)). Anybody know how this works or knows of a resource? Any help would be appreciated.

    You should look in the request parameter map, not the request attributes map. See ExternalContext.getRequestParameterMap() or use the JSF-reserved keyword param in your EL.

  • How to get values from a table(in jsp) for validation using javascript.

    hi,
    this is praveen,pls tell me the procedure to get values from a table(in jsp) for validation using javascript.
    thank you in advance.

    Yes i did try the same ..
    BEGIN
    select PROD_tYPE into :P185_OFF_CITY from
    magcrm_setup where atype = 'CITY' ;
    :p185_OFF_CITY := 'XXX';
    insert into mtest values ('inside foolter');
    END;
    When i checked the mtest table it shos me the row inserted...
    inside foolter .. Now this means everything did get execute properly
    But still the vallue of off_city is null or emtpy...
    i check the filed and still its empty..
    while mtest had those records..seems like some process is cleaining the values...but cant see such process...
    a bit confused..here..I tried on Load after footer...
    tried chaning the squence number of process ..but still it doesnt help
    some how the session variables gets changed...and it is changed to empty
    Edited by: pauljohny on Jan 3, 2012 2:01 AM
    Edited by: pauljohny on Jan 3, 2012 2:03 AM

  • Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?

    Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?

    Here is one solution:
    // mouse up action for submit button;
    function GetField(cName) {
    // get field object for cName field with error checking;
    var oField = this.getField(cName);
    if(oField == null) app.alert("Error accessing field named " + cName + "\nPleae verigy field name, spelling and capitalizeation.", 1, 0);
    return oField;
    } // end GetField function;
    var oPhone = GetField("phone");
    oPhone.required = oPhone.value == oPhone.defaultValue;
    var oEmail = GetField("email");
    oEmail.required = oEmail.value == oEmail.defaultValue;
    if(oPhone.required && oEmail.required) {
    app.alert("Missing required fields.", 1, 0);
    } else {
    app.alert("Submitting form", 3, 0);
    // additional code for submission;

  • HTMLB Form Validation using JavaScript

    Hi All,
    <b>
    I have created a portal appliaction using JspDynPage.
    I have created a form using HTMLB tags. I want to validate the inputfields before sending it to the server for processing.
    The validation has to be done using Javascript
    </b>
    <b> How do i got about this ??? </b>
    regards
    Brahmachaitanya

    I have written the following code to perform the validation.......
    <b>
    function validate()
              var funcName=htmlb_formid+"_getHtmlbElementId";
                func=window[funcName];
              var inpBox1 = eval(func('if1'));
              var eno=inpBox1.getValue();
              if(eno=='' || eno==null)
                   alert('Please Enter Employee Number');
                   htmlbevent.cancelSubmit=true;
              var inpBox2 = eval(func('if2'));
              var ename=inpBox2.getValue();
              alert(ename);
              if(ename=='' || ename==null)
                   alert('Please Enter Employee Name');
                   htmlbevent.cancelSubmit=true;
              var inpBox3 = eval(func('absencetype'));
              var atype=inpBox3.getValue();
              if(atype=='' || atype==null)
                   alert('Please Enter Absence Type');
                   htmlbevent.cancelSubmit=true;
              var inpBox4 = eval(func('if4'));
              var from=inpBox4.getValue();
              if(from=='' || from==null)
                   alert('Please Enter From Date');
                   htmlbevent.cancelSubmit=true;
              var inpBox5 = eval(func('if5'));
              var to=inpBox5.getValue();
              if(to=='' || to==null)
                   alert('Please Enter To Date');
                   htmlbevent.cancelSubmit=true;
              var inpBox6 = eval(func('if6'));
              var approve=inpBox6.getValue();
              if(approve=='' || approve==null)
                   alert('Please Enter Approver Name');
                   htmlbevent.cancelSubmit=true;
    </b>
    The problem now is that i am getting the <b> alert message only for Employee Number.</b>
    <b> I am not getting the alerts if I leave the the other fields blank </b>
    <b> How do i go about this ????????? </b>
    regards
    Brahmachaitanya

Maybe you are looking for

  • E130 - Migrate WIn 7 Pro to SSD

    Hi! I have a Lenovo Edge E130 and I have recently inserted a 128 GB SSD into the extra mSATA slot in addition to the 500 GB HDD. Now I want to migrate Win 7 Pro 64 bit and my programs from the HDD to the SSD, in order to start the laptop from the SSD

  • ABAP Exercises in SAP Netweaver 7.01 ABAP Trial Version

    Hello, I just finished the ABAP academy, courses TAW10 and TAW12. I want to do some exercises for studying to the certification test, but the exercises in the books require ABAP objects (such as tables, structures, data elements, templates and so on)

  • JSF 1.2 book

    Hi, is there any good book about JSF which covers also JSF 1.2? Or are the differences between 1.1 and 1.2 so important that I should buy 1.2-compliant book? Thank you

  • 11.2.0.3.0 Required Postinstallation Tasks: Downloading and Installing Patches

    I installed 11.2.0.3.0 on AIX 7.1. The postinstallation tasks begin with downloading and installing patches. I am not sure which patches or PSU to install. Following the directions in the installation guide, I go to My Oracle Support, then to Patches

  • Trial of Photoshop CS4 Extended Version

    Hi, I'm looking for a trial-version of Photoshop CS4 Extended Version to install it on my notebook. Problem is that I don't have any drive here, does someone know where I can get it?