Solved

onclick validation

Posted on 2000-05-14
14
2,084 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

705 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

20 Experts available now in Live!

Get 1:1 Help Now