Javascript validations problem

Ads

 
 

Share on Google+Share on Google+

ragavan
Javascript validations problem
0 Answer(s)      5 years ago
Posted in : Java Beginners

i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation works correctly but when my validation fails i am getting an alert window and i am reverting to next page. The thing is i want to stay in same page if validation fails. Do this favor for me. Thanks s advance

sports1.jsp file:-

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<HTML>
    <head>   
        <SCRIPT language="javascript">

function checkAll(field)
{
for (i = 0; i < field.length; i++)
    field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
    field[i].checked = false ;
}

function validate()
    {
    var chks = document.getElementsByName('checkk');
    var hasChecked = false;
    for (var i = 0; i < chks.length; i++)
    {
        if (chks[i].checked)
    {
        hasChecked = true;
        break;
    }
    }
    if (hasChecked == false)
    {
    alert("Please select atleast one Asset.");
    return false;
    }
    return true;
    }
function validate1()    
    { 
          if (document.myform.status.value=="0") 
     {
         alert("Please Select Status");
            return false;      
     }
        return true;
    }
 function validate2()
{

    validate1();
        validate();
} 

</script>
    </head>
    <body>

<FORM name="myform" method="POST" ACTION="sports.jsp" onsubmit="return validate2(this)">
<center>
<br>Select your AssetCode: </br>
<table>
<tr>
    <td>
        <input TYPE=checkbox name=checkk id="agree" VALUE=As10>
    </td>   
    <td>   
        As10
    </td>
    <td><select name="status">
<option value="0">Select</option>            
<option value="Activate">Activate</option>
<option value="Deactivate">Deactivate</option>
<option value="scrap">Scrap</option>

</select>
    </td>
    <td><INPUT TYPE=submit name=Convert Value="Convert" ></td>
</tr>

<tr>
    <td>
        <input TYPE=checkbox name=checkk id="agree" VALUE=As11>
    </td>   
    <td>   
        As11
    </td>

</tr>

<tr>
    <td>
        <input TYPE=checkbox name=checkk id="agree" VALUE=As12>
    </td>   

    <td>   
        As12
    </td>
</tr>

<tr>
    <td>
        <input TYPE=checkbox name=checkk id="agree" VALUE=As13>
    </td>   

    <td>   
        As13
    </td>
</tr>

<tr>
    <td>
        <input TYPE=checkbox name=checkk id="agree" VALUE=As14>
    </td>   

    <td>   
        As14
    </td>

</tr>
<tr>
    <td>

        <input type="button" name="SelectAll" value="SelectAll" onClick="checkAll(document.myform.checkk)">

    </td>
</tr>
<tr>
    <td>
        <input type="button" name="UnSelectAll" value="UnSelectAll" onClick="uncheckAll(document.myform.checkk)">

    </td>
</tr>
</table>
<br> 
</center>
</FORM>
</BODY>
</HTML>

sports.jsp file:-


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%! String[] asset; %>
<center><b>You have selected:</b> 
<% 
   asset = request.getParameterValues("checkk");
   if (asset != null) 
   {
      for (int i = 0; i < asset.length; i++) 
      {
         out.println ("<b>"+asset[i]+"<b>");
      }
   }
   else out.println ("<b>None<b>");
%>
</br>
<%
String selectedValue=request.getParameter("status");
out.println("Selected Status is: "+selectedValue);
%>
</center>
</body>
</html>
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
Javascript validations problem
Javascript validations problem  i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation...;HTML> <head> <SCRIPT language="javascript">
validations in javascript
validations in javascript  How do you check validations in javascript
Advertisements
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks in Advance, Sreenivasulu Arveti.   Hi, You can write normal JavaScript
validations
validations  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
how to perform the client side validations to the dropdown list using javascript?
how to perform the client side validations to the dropdown list using javascript?  Hi Good Morning! This is Prasad, I want to perform the client side validation to the dropdown list using javascript. So give me sample.I am
Validations
Validations  Javascript validation is working fine in Internet... = "Javascript"> function checkEmail() { if (/^\w...;script language = "Javascript"> function checkEmail
Javascript problem - WebSevices
Javascript problem  Hai friends, I have nearly 16 text... before submitting the form with the condition of being empty. PROBLEM:-->... friend, Please specify the problem : You want to return back same page
javascript code problem - JSP-Servlet
javascript code problem  Thanks for sending answer.but actually what u send is not my actual requirement.first look this code. Subject... hidden variable and write javascript code so that all tables values are added
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
java validations
" /> <script type="text/javascript"> function validateForm...; if (f.length<20) { alert("Address too short"); return false; } var q=document.retailer.contact_no.value; if (q==null || q=="") { alert
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
Im not getting validations - Struts
in s-c.xml But Im unable to get validations This is my validation.xml file...("failure"); } } } plz tell me where is the problem... Im unable to trace the problem.... BeCoz..Im new to Struts... Thanks InAdvance
Custom Validations - Struts
Custom Validations  Hi, I am trying to do the custom validations in struts 1.1.That is how can we plug in our own custom validations into Validator ? Can anybody tell me how to do this with a sample example. Thanks
Multiple Validations on jTestFields
Multiple Validations on jTestFields  Hi, I am working on an window application in which I have to validate the data of text fields, like if textbox1... then it should check whether it is valid or not. Unless all the validations
struts validations - Struts
struts validations  hi friends i an getting an error in tomcat while running the application in struts validations the error in server as validation disabled plz give me reply as soon as possible.  Hi friend
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
validations in struts - Struts
validations in struts  hi friends plz give me the solution its urgent I an getting an error in tomcat while running the application in struts validations the error in server as "validation disabled" plz give me reply as soon
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
JavaScript
JavaScript  clone JavaScript
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
javascript
javascript  write a program to display implement about browsers using javascript