Solved

onclick validation

Posted on 2000-05-14
14
2,091 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

752 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