Question: Javascript validations problem

Ads

 
 
 

Share on Google+Share on Google+

ragavan
Javascript validations problem
0 Answer(s)      4 years and 7 months 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:-

<[email protected] 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:-


<[email protected] 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
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
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
Validations
Validations  Javascript validation is working fine in Internet... = "Javascript"> function checkEmail() { if (/^\w...;script language = "Javascript"> function checkEmail
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
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
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
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
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
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
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
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
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
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
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
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
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
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
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads