Compare two values input by user in JavaScript

Hi, there,
I have two text input boxes in my form, and user can input some value in the boxes. I want to check if the values in these two boxes are numerical and compare them in my JavaScript function. How can I do this?
Thanks in advance.
Fred

Hi,
You can make use of this code. You can user parseInt, which parses a string argument and returns an integer of the specified base.
<html>
<head>
<script>
function testCompare()
var x = parseInt(document.myFrm.a.value);
var y = parseInt(document.myFrm.b.value);
if( x > y)
alert ("X is greater");
else
alert("Y is greater");
</script>
</head>
<body>
<form name = myFrm>
<input type = text name = a value = 100>
<input type = text name = b value = 200 >
<input type = button value = click onclick = testCompare()>
</form>
</body>
</html>
Hope this helps.
Thanks,
Senthil_Slash

Similar Messages

  • SSRS Expression to compare two values and get data from another dataset

    Hi,
    I have a requirement where in i need to compare a value of a dataset (not the one which table is poiting to)
    with the value of a text box, and return the count if it matches else 0, the expression is as below. Here 
    industryName and recCount are from the dataset ds_MedimOrLowImpactEntities.  whats wrong in this expression
    =Sum(IIF(Fields!industryName.Value = reportItems!hpapra_name.Value, Fields!RecCount.Value, 0), "ds_MediumOrLowImpactEntities")
    This is the error that i am getting:
    Any help on this is appreciated
    Kruthi Hegde

    Hi Kruthi,
    After testing the issue in my local environment, I can reproduce it. Just the error message said, “Aggregate function can be used only on report items contained in page headers and footers”. So the sum function that contains report items should be stayed
    at page headers or footers. Besides, you said the hpapra_name textbox contain a field from another dataset, not the ds_MedimOrLowImpactEntities dataset. While in Reporting Services, Report item expressions can only refer to other report items within the same
    grouping scope or a containing grouping scope. So consider the two issues, we should use some other expression to instead the “reportItems!hpapra_name.Value” expression.
    Take a look at the "Looking up values from another dataset" topic here:
    http://msdn.microsoft.com/en-us/library/ms159673.aspx#LookupFunctions
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Comparing two values in a jsp file.

    Hi every one.
    How can i compare to values ,one of them is picked up from a database and the second is passes to this page from html form as a parameter.
    e.g
    <c:when test="${param.password==user.password} ">
    i did it like that but it dosen't work .if i replaced one of them with an actual value like "123466" it work.is there some thing like String.equalsIgnoreCase() function
    to use it in such situations.
    thnx for any help.

    <c:when test="${param.password==user.password} ">instead try this..
    <c:when test="${param.password.equals(user.password)} ">

  • Compare Two Values in logic:equal issue !!!!!!!!!!!

    Hi Techie !!!!
    I have list object from DB inwhich i want compare a field in <logic:equal> Struts EL ....... I have written the following code.....
    <%
             List list = (List)request.getAttribute("AppointmentDetailNavigationList");
          pageContext.setAttribute("list", list, pageContext.REQUEST_SCOPE);
    %>
    <body>
    <ul>
         <logic:iterate id="item" name="list" type="com.bean.AppoinmentInformation" scope="request">
               <logic:equal property="rsc_name" value="rsc_name">   // This is for test only
                         *// Here i want compare rsc_name if comes two times in list i want come out of this scope....*
               </logic:equal>
         </logic:iterate>
    </ul>
    </body>
    </html>          My requirement is a field with duplicate, wanna come out of the scope from the list...
    Any one help me out.....

    Wouldn't it be easier to use a Set which does not allow duplicates? That would nip the problem at the source rather than bringing it all the way to the jsp and not displaying it.
    However if you have to have it this way, there is no easy way to break out of a loop in logic tags. Maybe some murky servlet code with a break command in scriptlets would do the trick, but you really have to scour the source code to confirm that.
    cheers,
    ram.
    Edited by: Madathil_Prasad on Apr 26, 2010 1:00 PM

  • UDF to compare two values and Pull another value if equals

    Hi all,
    I am looking for UDF to perform the following logic, please help me
    I will have 3 inputs, say field1, fields2, field3. If field1 = field2 then return field3.
    You may say that this can be implemented by message mapping with IF condition itself. But here field1 & field2 are from different segments.Field1 & field3 are from same segment.
    When i use message mapping because of this context problems, i am able to get this validation for the first set only.
    If i have the multiple values means, i am not able to get it.
    all these field1, field2 & field3 are multiple times
    Regards
    Suman gupta

    Chirag,
    I set the all 3 input's context to parent level and now error is not there.which is fine
    But i am not getting output even though field1 & field2 are equal/
    The logic should be in this way.
    Record1:
    ABC(segment)
       <Field2>01</field2>
      <Field1>20101110</field3>
    XYZ(segment)
         <Field1>10</field1>
    Record2:
    ABC(segment)
       <Field2>10</field2>
       <Field1>20090909</field3>
    XYZ(segment)
       <Field1>01</field1>
    In the above case Record1-field1 should check whether Record1-field1==Record1-field2 ?? NO
    Record1-field1==Record2-field2?? YES the return 20090909
    And
    Record2-field1 should check whether Record2-field1==Record2-field2 ???? NO
    Record2-field1==Record1-field2 ??? YES then return 20101110.
    Please let me know, i am not able to achieve this using graphical Mapping, thats why i am thinking about UDF.
    Regards

  • Comparing  Two Items in javascript

    I TRY BELOW CODE BUT IT IS NOT WORKING , PLEASE HELP ME TO COMPAR TWO VALUE OF ITEM WITH JAVASCRIPT
    WHAT CHANGE I HAVE TO DO , IN BELOW CODE.
    LOGIC IS IF P25_VAL1 = P25_VAL2 THEN MQTY = SQTY
    function mfgsal()
    function getVal(item){
    if($x(item).value != "")
    return parseFloat($x(item).value);
    else
    return 0;
    if ( parseInt($v('P25_VAL1')) = ( parseInt($v('P25_VAL2'))) {
    $x('P26_SQTY').value =
    ($x('P26_MQTY').value );
    }

    Kanaiya Sindhavad wrote:
    I TRY BELOW CODE BUT IT IS NOT WORKING , PLEASE HELP ME TO COMPAR TWO VALUE OF ITEM WITH JAVASCRIPT
    WHAT CHANGE I HAVE TO DO , IN BELOW CODE.
    LOGIC IS IF P25_VAL1 = P25_VAL2 THEN MQTY = SQTYDon't shout, and always post code wrapped in <tt>\...\</tt> tags.
    if ( parseInt($v('P25_VAL1')) = ( parseInt($v('P25_VAL2')))"=" is the assignment operator in JavaScript, not used to test for equality. And the brackets dont match. It should be "===" (comparing both type and value):
    if ( parseInt($v('P25_VAL1')) === parseInt($v('P25_VAL2')))

  • Need ideas for alternative to JavaScript for comparing two inputText values

    Hello
    I am currently using the JavaScript method to check if the values of two inputText components are equal.
    If the values are not equal an alert box is displayed. In either case the action on the bean is performed and in the action method the two bean property values are compared again, if they don't match the action returns null and the for is redisplayed.
    I don't like this method because:
    A) it seems long winded and wasteful
    B) the JavaScript dialog box is out of character with the rest of the form, where validation errors are returned as messages next to the offending component.
    On one of the inputText components I already do a custom validation to check that the input value is a valid javax.mail.internet.InternetAddress.
    Does anyone know of any other method ideas, perhaps using Value Change Events that will allow a message to be written against the second inputText component if the two values did not match, and which could be done before the Invoke Application event. I have tried something along these lines but have failed.
    Many thanks in advance...

    If you can use a custom tag for the validator instead of the standard f:validator tag,
    there is a better way:
    The custom tag has an attribute , eg. "forId", to specify the ID of another component.
    Then, your validator can use the attribute for the parameter of findComponent().
    Something like:
    YourValidatorTagHandler.java
         protected Validator createValidator() throws JspException {
              YourValidator val = (YourValidator)super.createValidator();
              val.setForId(forId);
              return val;
    YourValidator.java
         public void setForId(String f) {
              forId = f;
         public void validate(
              FacesContext context,
              UIComponent component,
              Object value)
              throws ValidatorException {
                   int i1;
                   int i2;
                   try {
                        i1 = ((Integer) value).intValue();
                        UIComponent comp = component.findComponent(forId);
                        String val = (String)((UIInput)comp).getSubmittedValue();
                        i2 = Integer.parseInt(val);
                   } catch (RuntimeException e) {
                        FacesMessage msg = new FacesMessage(e.getMessage());
                        throw new ValidatorException(msg);
                   if (i1 != i2) {
                        FacesMessage msg = new FacesMessage("Error");
                        throw new ValidatorException(msg);
         }

  • Retreive the values from a user Input Popup before planning layout

    Hi all,
    The user run a planning layout and is coming the popup where he can choose :
    Cost Center
    Currency .
    Is there any function module between executing the popup and showing the layout.
    I have to create a function module to check the entries of the users.
    Regards

    Frank,
    There are multiple ways to ensure that the values entered by the users are valid. A few of them are:
    1. Restrict values for users with in SEM planning area.
    2. Write custom code to restrict values in dropdown list.
    3. Another  way of doing it is by using two sets of variables. One for input by users and the other for passing the values in the planning level. The user would enter a value, the code for passing the value to the planning level, would check the data entered and then either pop up an error message or refresh the layout with the data.
    As mentioned, the approach would depend on the specfic need and the design of the planning application.
    Sunil

  • How to get the values inputted by the user in Classification view of  MM02

    Hello,
    Does anyone know how to get the inputted values in Classification view of MM02/MM01? I tried to use CLAF_CLASSIFICATION_OF_OBJECTS but this gets the values that is currently saved in the tables and not the values that the user recently inputted in the screen.
    Regards,
    Alfred

    hi
    try this...
    How to Display the Batch Characteristics in BOM?

  • Compare two input text in adf

    Hi
    i used the Build JDEVADF_11.1.1.4.0
    I want to make compare  validation between two  input text  Are equal or not . same Thing when i create new email i must enter the password and re enter password if not   equal  he give me message

    Hi,
    for a validation String, you can put autosubmit=true and in the valuechangeListener make the comparation.
    How to compare two Strings in java? http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

  • How to  Get input from  User and Display it's Value

    Hi ,
    I need to get 2 inputs from user and to display it's Mutilple Value.
    The Below Code is working fine to get 2 Input's from user,but it display a Junk value as a Result .How to
    overcome this Problem. I need to display it's Mutilple(a*b) value of "a " and " b".
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws IOException{
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
    do{
    a=(char)br.read();
    Count++;
    b=(char)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);
    }

    Changed to Integer but still the problem persists.
    import java.io.*;
    class Mul{
    static int a=0;
    static int b=0;
    static int Count=0;
    public static void main(String args[])throws IOException{
    BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
    do{
    a=(int)br.read();
    Count++;
    b=(int)br.read();
    if(Count==2)
    System.out.println("The Multiplied Value is "+a*b);
    }while(Count<2);
    }

  • Compare two text box values????

    Hello All,
    I do have one logic, but not sure where to write it so want your guys help for the same.
    The logic is:-
    if (&P13_NEW_PASSWORD. == &P13_CONFIRM_NEW_PASSWORD.) then
    insert into tbuser (password) values (&P13_NEW_PASSWORD.);
    else
    dbms_output.line_('Both the text boxes should be same!!')
    P13_NEW_PASSWORD and P13_CONFIRM_NEW_PASSWORD are two text boxes, where in above statment I'm comparing two text box values, if yes than insert that values into the DB tables otherwise displaying else messges.
    so can anybody tell me where should i write the above logic to make it work perfect..!!!
    thanks
    regards,
    Kumar

    Kumar,
    I'm glad you asked! Here's a great blog post on a custom auth scheme that hashes passwords:
    http://djmein.blogspot.com/2007/07/custom-authentication-authorisation.html
    I would suggest a few changes to the "get_hash" function. First, the DBMS_OBFUSCATION_TOOLKIT has been deprecated in favor of DBMS_CRYPTO:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_crypto.htm
    http://www.psoug.org/reference/dbms_crypto.html
    DBMS_CRYPTO offers Message Authentication Code (MAC) functions which are keyed hashes. If you use a non-keyed function such as MD5 (which is VERY well known), someone can easily generate a table of all possible passwords within reason and their matching hash, which essentially allows them to get the passwords. MAC functions take in the data (password in this case) and a key. You can probably just use a big random string for your key. Now someone would need to the key as well to generate a hash table. In short, just use DBMS_CRYPTO.MAC where Duncan used DBMS_OBFUSCATION_TOOLKIT.md5.
    Tyler

  • Compare two dropdownlists values with each other!!!!!!

    Hi ,
    I have two dropdown s with some values i want to compare two dropdowns values. I have java script on the click event of the button it will compare values of drodpowns. If any redundant/duplicate value found then those values need to be deleted from the second dropdown.
    function dummy()
    var dd1=xfa.resolveNode(form1.Page1.State.somExpression);       //path to first dropdown
    var dd2 = xfa.resolveNode(form1.Page1.Dummy.somExpression);  //path to second dropdown
    var i =0;
    var j=0;
    if(State.length!= 0)//State is first dropdown
         for (;i<dd1.length;i++)
              for(;j<dd2.length;j++)
                   if(dd1.getDisplayItem(i)==dd2.getDisplayItem(j))
                       dd2.deleteItem(j);   //deleting the value from second dropdown.
                        break;
                   else
                        continue;
    But this function is not working properly it is taking first value of the DD1 and comapring with all the values of DD2 and coming out of the loop .There are other values in the DD1.So for that comapring is not happening.
    Please help me !!!
    Thanks in advance,
    Bharathi.

    Hi,
    You just need to re-initialise the j variable each time though the i loop.  As you have it the second time around j will already be equal to dd2.length so will skip the inner loop.
    try
    for(var j=0;j<dd2.length;j++)
    Regards
    Bruce

  • Compare two strings for partial or full match

    I have been trying to figure out away of comparing two strings.
    I can get the full string matching to successfully work but am struggling on how to get partial eg wildcard search working.
    say I had names like paul Duncan, George Morrison.
    I have split them up so its now paul , duncan i then use the users entered string to compare it against the name name to see if it matches anything in the first name or the last name if it does i added it to an arraylist.
    however i have tried t use a indexof as i believe this looks for similarity (Substring matches?) but it always returns -1.
    Could anyone possibly direct me to a method that will allow me to use partial text string to match it against stored user names.
    eg user enters pa
    I would return anything that would contain pa
    thanks for any help

    thank you for the reply
    Sorry I forgot to put in the code.
    This is a reduced down version including the read in from a text file as well as the index of if statement and the adding of it to an array list.
    public class FindContact {
    String res;
    /** Creates a new instance of FindContact */
    public FindContact() {
    public Object[] FindAUser(String passSearch) {
    System.out.println("getting here");
    ArrayList found = new ArrayList();
    String patternStr = ",";
    int j, i = 0;
    try {
    BufferedReader in = new BufferedReader(new FileReader("H:\\out.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String[] fields = str.split(patternStr);
    //for(j=0;j < fields.length;j++) {
    if (fields.length != 0) {
    if (passSearch.indexOf(fields[0])!=-1 || passSearch.indexOf(fields[1])!=-1) {
    found.add(str);
    System.out.println("ENDDDDDDDD value ");
    in.close();
    } catch (IOException e) {
    System.out.println(e.toString());
    Object[] foundResult = new Object[found.size()];
    foundResult = found.toArray();
    if (foundResult.length >= 0) {
    System.out.println(foundResult.length);
    return foundResult;
    Hope that helps as it has confused me and am not sure why it is not returning a value.
    Should I maybe use the contain method instead to search for the user inputted string?

  • How to COmpare two variable in BPEL

    Hi ,
    I have two compare two variable ( EIN field ) one from input variable of a BPEL process and other one the output variable of a invoke .
    My requiremet is like this :
    If the the value of both EIN field is same then I have to assign Name field of Invoke output parameter to Output variable of BPEL process .
    If the value doesn't match then i have to assign ' No Data Exist ' expression to Output variable of BPEL process .
    How can i do this .
    Please help me regarding this as early as possible .

    You can do this in a switch statement. Perform a comparision to check if the values are the same, if case is not important (because users will enter anything) wrap the code in a case expression, e.g. upper(user_date) = upper(file_data)
    What version of SOA Suite and JDev are you using. Make sure that these versions are in sync.
    cheers
    James

Maybe you are looking for