Solved

onclick validation

Posted on 2000-05-14
14
2,094 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

628 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