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 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>
View Answers









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... JavaScript validation, but change the error/information message as per your local
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
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  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
Validations
Validations  Javascript validation is working fine in Internet... = "Javascript"> function checkEmail() { if (/^\w...;script language = "Javascript"> function checkEmail
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
Validations
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
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
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
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
JavaScript
JavaScript  clone JavaScript
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
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
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
ModuleNotFoundError: No module named 'tripleo-validations'
ModuleNotFoundError: No module named 'tripleo-validations'  Hi, My... named 'tripleo-validations' How to remove the ModuleNotFoundError: No module named 'tripleo-validations' error? Thanks   Hi
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
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
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
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help me.how to learn
javascript
javascript  hi sir, if i want to learn javascript. what concepts i want to know
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
javascript
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
javaScript
javaScript  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
javascript
javascript  passing javascript values to jsp   Hi Friend, Try the following code:ADS_TO_REPLACE_1 form.jsp: <html> <script>... Javascript value In JSP"> <% String st=request.getParameter("msg"); if(st
Javascript
this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function..." method="post" onsubmit="javascript:return validate();"> Phone Number:<
Javascript
Javascript  Dear Sir, Thank You a lot for your continuos support.Again i am in need of your help. What is the javascript code to disable a link,once... javascript or css Please help me.Urgent Regards Debasis   Hello Friend
Javascript
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length
javascript
javascript
javascript  how to create random question using javascript?   <html> <script> function displayQuestions() { document.getElementById("text").value=" "; var Questions = new Array(20
javascript
javascript
javascript  Hi deepak, sample example on javascript form validation   <html> <script> function checkName(text) { if(isNaN(text)){ return 1; } else{ alert("Please enter a valid name. The only charachters
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

Ads