Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

onclick validation

Posted on 2000-05-14
14
Medium Priority
?
2,098 Views
Last Modified: 2008-03-04
<script language="JavaScript">
      function check (idform,value1,value2){
            if (int(value1) > int(value2)) {
                  alert ("Sell Notify price must be equal or greater than Buy Notify price")
            }else {
                  idform.Submit()
            }      
      }
</script>

-----------
        <input type="text" name="stock" size="15"></font></td>
        <td width="80" align="center" height="1"><font face="Verdana" size="2">
        <input type="text" name="price" size="15"></font></td>
      <td width="80" align="center" height="1"><font face="Verdana" size="2">
        <input type="text" name="share" size="15"></font></td>
        <td width="80" align="center" height="1"><font face="Verdana" size="2">
        <input type="text" name="bnotify" size="15"></font></td>
        <td width="80" align="center" height="1"><font face="Verdana" size="2">
        <input type="text" name="snotify" size="15"></font></td>
      <td width="80" align="center" height="1"><font face="Verdana" size="2">
        <input type="text" name="date" size="15"></font></td>       



<input type="button" value="Add" name="add" size="200" onclick="check(this.form,this.form.bnotify,this.form.snotify)">

it generates error :
Object expected

what's wrong, Please help

 thanks
0
Comment
Question by:Dewi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 4

Expert Comment

by:rafistern
ID: 2809544
int() is not recognised in JavaScript. Use Math.floor() instead (rounds down) or Math.ceiling() (rounds up) or Math.round() (rounds to nearest integer.

Rafi
0
 

Author Comment

by:Dewi
ID: 2809567
Hi rafistern,

Thanks for your reply
unfortunatelly, It still not work,
Now, It generates error : Object doesn't support this property or method
on line 9

 thanks
0
 
LVL 4

Expert Comment

by:rafistern
ID: 2809636
Next problem:

You are passing
this.form.bnotify,this.form.snotify

instead of
this.form.bnotify.value,this.form.snotify.value

Which line is line 9?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Dewi
ID: 2809660
Hi rafisten,

I have passing this.form.bnotify.value
but still not work

line 9 :
if (Math.Round(value1) > Math.Round(value2)) {

<script language="JavaScript">
      function check (idform,value1,value2){
            if (Math.Round(value1) > Math.Round(value2)) {
                  alert ("Sell Notify price must be equal or greater than Buy Notify price")
            }else {
                  idform.Submit()
            }      
      }
</script>
0
 
LVL 1

Expert Comment

by:sureshkumar
ID: 2809661
<html>
<head>
<script language="JavaScript">
function check (form){
if (parseInt(form.elements[3].value) > parseInt(form.elements[4].value)) {
alert ("Sell Notify price must be equal or greater than Buy Notify price");
}
}
</script>
</head>
<body>
<form name=idform>
<table>
<tr>
<td><input type="text" name="stock" size="15"></font></td></tr>

<tr><td width="80" align="center" height="1"><font face="Verdana" size="2">
<input type="text" name="price" size="15"></font></td> </tr>

<tr><td width="80" align="center" height="1"><font face="Verdana" size="2">
<input type="text" name="share" size="15"></font></td> </tr>

<tr><td width="80" align="center" height="1"><font face="Verdana" size="2">
<input type="text" name="bnotify" size="15"></font></td> </tr>

<tr><td width="80" align="center" height="1"><font face="Verdana" size="2">
<input type="text" name="snotify" size="15"></font></td> </tr>

<tr><td width="80" align="center" height="1"><font face="Verdana" size="2">
<input type="text" name="date" size="15"></font></td></tr>

<tr><td>
<input type="button" value="Add" name="add" size="200"
onClick="check(this.form)"> </td>
</tr>
</table>
</form>
</body>
</html>

further queries
suresh
0
 

Author Comment

by:Dewi
ID: 2809694
Adjusted points from 20 to 30
0
 

Author Comment

by:Dewi
ID: 2809695
Hi suresh,

Thanks for your answer.
your parseint is working well.
but my code still generates an error on line 12:

idform.Submit()

look at my previous code
I need to submit the form if value1 < value2. how to do this ?

Thanks
0
 
LVL 2

Expert Comment

by:indu_ma
ID: 2809903
Actually in ur code that u have given i check the form tag itself is missing may be u missed it while copying the code or u have not even given it.
Check ur code for the <form> tag.

0
 
LVL 2

Expert Comment

by:indu_ma
ID: 2810011
Include the form tag

<script language="JavaScript">
function check (idform,value1,value2){
if (int(value1) > int(value2)) {
alert ("Sell Notify price must be equal or greater than Buy Notify price")
}else {
idform.Submit()
}
}
</script>

---------------------------------
I HOPE U MISSSED THIS LINE OF CODE
<form name=myform action=page.asp method=post>
-----------------------------------
  <input type="text" name="stock" size="15"></font></td>
  <td width="80" align="center" height="1"><font face="Verdana" size="2">
  <input type="text" name="price" size="15"></font></td>
      <td width="80" align="center" height="1"><font face="Verdana" size="2">
  <input type="text" name="share" size="15"></font></td>
  <td width="80" align="center" height="1"><font face="Verdana" size="2">
  <input type="text" name="bnotify" size="15"></font></td>
  <td width="80" align="center" height="1"><font face="Verdana" size="2">
  <input type="text" name="snotify" size="15"></font></td>
      <td width="80" align="center" height="1"><font face="Verdana" size="2">
  <input type="text" name="date" size="15"></font></td>    



<input type="button" value="Add" name="add" size="200" onclick="check(this.form,this.form.bnotify,this.form.snotify)">
</form>

0
 
LVL 1

Expert Comment

by:sureshkumar
ID: 2810069
hey dewi,

just change code :

<script language="JavaScript">
function check (form){
if (parseInt(form.elements[3].value) > parseInt(form.elements[4].value)) {
alert ("Sell Notify price must be equal or greater than Buy Notify price");
}
else
{
form.submit();
}
}
</script>

0
 

Author Comment

by:Dewi
ID: 2810246
Adjusted points from 30 to 50
0
 

Author Comment

by:Dewi
ID: 2810247
Hi indu_ma, thanks for your answer.
no there is nothing todo with form tag
the problem is on JavaScript
look at suresh previous comment.

Hi suresh,

Here it is, my latest code,
You see, there is no difference between yours and my code, but still not work.

It generates error on line 12 :
idform.Submit()
object doesn't suupport this property of method

after i debug using visual interdev then it generates error : An exception of type 'Microsoft JScript run time error: Object doesn't support this property or method " was not handled


<script language="JavaScript">
      function check (idform,value1,value2){
            if (parseInt(value1) > parseInt(value2)) {
                  alert ("Sell Notify price must be equal or greater than Buy Notify price")
            }else {
                  idform.Submit()
            }      
      }
</script>

<input type="button" value="Add" name="add" size="200" onclick="check(this.form,this.form.bnotify.value,this.form.snotify.value)">


 

0
 
LVL 1

Accepted Solution

by:
sureshkumar earned 200 total points
ID: 2810300
hey dewi,

give in small letters

idform.submit();

0
 
LVL 3

Expert Comment

by:bark10
ID: 2811059
This works with onClick="return validate()"  and changing 'myform' to your form name:

<script language="JavaScript">
function check ()
{
      if (parseInt(myform.bnotify.value) > parseInt(myform.snotify.value))  
            {
            alert ("Sell Notify price must be equal or greater than Buy Notify price")
            return false;
            }
       return true;
}

function validate()
{
      if (check())
            myform.submit();
}
</script>
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question