Solved

onclick validation

Posted on 2000-05-14
14
2,085 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is assert.deepEqual? 4 39
JS Plugin Chaining 2 32
Enter key on html form page 11 42
Angular- typeahead works but need to change 2 things 5 17
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now