473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

passing condition

ddtpmyra
333 100+
on my function script i wanted to direct my page into another when it passes my condition.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function show_alert()
  4. if (x > y)
  5.   {
  6.     alert ('value is okay');
  7.     // what code to place here when i want to direct it to the next page?
  8.   }
  9. }
  10. </script>
  11.  
  12. <form method="post">
  13. <input type="submit" onclick="show_alert()" />
  14. </form>
Nov 13 '09 #1

✓ answered by gits

you need to do a operation with the values ...
Expand|Select|Wrap|Line Numbers
  1. alert ('your are over by: ' + (x-y));

23 1740
gits
5,390 Expert Mod 4TB
you may use:

Expand|Select|Wrap|Line Numbers
  1. window.location.href = 'whateverUrl';
kind regards
Nov 13 '09 #2
acoder
16,027 Expert Mod 8TB
Alternative:

Since this is going to be called via a form submit, set the form action and then return true when the condition is met, and false otherwise. That way, this will work even if JavaScript is disabled.
Nov 13 '09 #3
ddtpmyra
333 100+
@acoder

any simple code you can share :)

thanks!
Nov 13 '09 #4
ddtpmyra
333 100+
@gits
hi Gits!
this is not working :( this is what i did
Expand|Select|Wrap|Line Numbers
  1. if (x>y)
  2.   {
  3.     alert (x-y);
  4.   }
  5. else
  6.   {
  7.    window.location.href = 'home.php'; 
  8.   }
  9.  
  10.  
Nov 13 '09 #5
ddtpmyra
333 100+
@acoder
Here what I have in placed
Expand|Select|Wrap|Line Numbers
  1. <form action="home.php" onsubmit="return validate_form()" method="post">
JS
Expand|Select|Wrap|Line Numbers
  1. function validate_form()
  2. {
  3. x=   parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value);
  4. y = parseInt(document.getElementById('ActualAttendees').value)
  5.  
  6. if (x>y)
  7.   {
  8.     alert (x-y);
  9.   }
  10. else
  11.   {
  12.    window.location.href = 'home.php'; 
  13.   }
  14.  
  15. }
Nov 13 '09 #6
gits
5,390 Expert Mod 4TB
what is the code exactly supposed to do? or better ... what exactly do you want to achieve?

kind regards
Nov 13 '09 #7
ddtpmyra
333 100+
If the x is less than y... I wanted to allow the user to view the page (or html)
Nov 13 '09 #8
gits
5,390 Expert Mod 4TB
then you should return false in the other case ...
Nov 13 '09 #9
ddtpmyra
333 100+
can you show here how?
Nov 13 '09 #10
gits
5,390 Expert Mod 4TB
put:
Expand|Select|Wrap|Line Numbers
  1. return false;
after your alert ...

kind regards
Nov 13 '09 #11
ddtpmyra
333 100+
It works! Thanks a lot!
Nov 13 '09 #12
gits
5,390 Expert Mod 4TB
glad to hear that :)
Nov 13 '09 #13
ddtpmyra
333 100+
just a follow-up... now on my alert box i wanted to put string and variable value. I did this changes below but it doesnt take effect what else to do?
Expand|Select|Wrap|Line Numbers
  1. if (x>y)
  2.   {
  3.     alert ('your are over by:' x-y);
  4.     return false;
  5.   }
  6. else
  7.   {
  8.      alert (x);
  9.      return true;
  10.   }
  11.  
Nov 13 '09 #14
gits
5,390 Expert Mod 4TB
you need to do a operation with the values ...
Expand|Select|Wrap|Line Numbers
  1. alert ('your are over by: ' + (x-y));
Nov 13 '09 #15
ddtpmyra
333 100+
Hello Bytes:

Here's a continuation of my dilema :)
Now it works fine but Im planning to put more functionality on my JS script so Im planning to have a 'header JS' to call the subs functions. The problem is that it do call the the sub function but it let the browser go to the next page even though the condition didn't pass to return true. Please help. Thanks in advance!

The button Form
Expand|Select|Wrap|Line Numbers
  1. <form method="post" name="recapform" action="tblevent_entry_recap_handler.php?id=<?php echo $_GET['id'];?> " onsubmit="return show_alert()">
  2.  
header function
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function show_alert()
  3. {
  4. entity_alert();
  5.  
  6. }
  7. </script>
  8.  
sub function
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function entity_alert()
  3. {
  4. x=  parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
  5.     +parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
  6.     +parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
  7.     +parseInt(document.getElementById('ResidentialFacility').value);
  8.  
  9. y = parseInt(document.getElementById('ActualAttendees').value)
  10.  
  11. if (x>y)
  12.   {
  13.     alert ('Entity is over by:' + (x-y));
  14.     return false;
  15.   }
  16. else
  17.   {
  18.          return true;
  19.   }
  20.  
  21. }
  22. </script>
  23.  
Nov 17 '09 #16
acoder
16,027 Expert Mod 8TB
In show_alert(), add a return:
Expand|Select|Wrap|Line Numbers
  1. return entity_alert();
Nov 18 '09 #17
ddtpmyra
333 100+
It works but when I added more function underneath in only perform the most top functionalities... am i doint this correctly?

header function
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function show_alert()
  3. {
  4. return entity_alert();
  5. return age_alert();
  6.  
  7.  
  8. }
  9. </script>
sub functions
Expand|Select|Wrap|Line Numbers
  1. function entity_alert()
  2. {
  3. x=  parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
  4.     +parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
  5.     +parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
  6.     +parseInt(document.getElementById('ResidentialFacility').value);
  7.  
  8. y = parseInt(document.getElementById('ActualAttendees').value)
  9.  
  10. if (x>y)
  11.   {
  12.     alert ('Entity is over by:' + (x-y));
  13.     document.getElementById('Organization').focus();
  14.     return false;
  15.   }
  16. else
  17.   {
  18.          return true;
  19.   }
  20.  
  21. }
  22. </script>
  23.  
  24.  
  25. <!--- 2nd function -->
  26. <script type="text/javascript">
  27. function age_alert()
  28. {
  29. tAge=  parseInt(document.getElementById('Under18').value)+parseInt(document.getElementById('Eighteen34').value)+parseInt(document.getElementById('ThirtyFive54').value)+parseInt(document.getElementById('FiftyFour').value);
  30.  
  31. a = parseInt(document.getElementById('ActualAttendees').value)
  32.  
  33. if (tAge>a)
  34.  {
  35. alert ('Age Group is over by:' + (tAge-a));
  36. document.getElementById('Under18').focus();
  37. return false;
  38.   }
  39. else
  40.  {
  41.  return true;
  42.   }
  43.  
  44. }
  45. </script>
  46.  
Nov 18 '09 #18
acoder
16,027 Expert Mod 8TB
Once you return, it won't execute any more statements.

Try something like:
Expand|Select|Wrap|Line Numbers
  1. return (funA() && funB());
Nov 19 '09 #19
ddtpmyra
333 100+
@acoder
Here's what I did below but it only performs the first function. Anything do i have to do on sub functions?

Header
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function show_alert()
  3. {
  4. return (age_alert() && entity_alert());
  5. }
  6. </script>
sub two functions :
1).
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function entity_alert()
  3. {
  4.         tEntity=  parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
  5.             +parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
  6.             +parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
  7.             +parseInt(document.getElementById('ResidentialFacility').value);
  8.  
  9.         y = parseInt(document.getElementById('ActualAttendees').value);
  10.  
  11.     if (tEntity>y)
  12.           {
  13.             alert ('Entity is over by:' + (tEntity-y));
  14.                 return false;
  15.               }
  16.                 else    
  17.               {
  18.                  return true;
  19.               }
  20. }
  21. </script>
2).

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function age_alert()
  3. {
  4.         y = parseInt(document.getElementById('ActualAttendees').value);
  5.         tAge=  parseInt(document.getElementById('Under18').value)+parseInt(document.getElementById('Eighteen34').value)+parseInt(document.getElementById('ThirtyFive54').value)+parseInt(document.getElementById('FiftyFour').value);
  6.     if (tAge>y) {
  7.                 alert ('Age Group is over by:' + (tAge-y));
  8.                 return false;
  9.                   }
  10.  
  11.     else         {
  12.                  return true;
  13.                 }
  14. }
  15. </script>
Nov 19 '09 #20
acoder
16,027 Expert Mod 8TB
If age_alert() returns false, it won't go to entity_alert() because there's no need.
Nov 20 '09 #21
ddtpmyra
333 100+
@acoder
Please tell me what the best way to handle this two conditions before it let the user to go to the next page?
Nov 20 '09 #22
acoder
16,027 Expert Mod 8TB
Find a scenario when the first function should return true and the second false to see if it works.
Nov 21 '09 #23
ddtpmyra
333 100+
I just redo it and make it simplier and it works perfectly fine. Thanks for all of your inputs ACECODE

Expand|Select|Wrap|Line Numbers
  1.  
  2. if  ((a<=y) && (b<=y) && (c <=y) && (d<=y)  && (Ustatus=='Complete'))
  3.  {   
  4. return true; 
  5.   }
  6. else {   alert ('Please check your entry total and event status');
  7. return false;
  8. }
Dec 1 '09 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Newbie | last post by:
Hi, I am using creating a drop down menu populated by a call to a postgresql database. The drop down menu is populated correctly (or appears to be) and then upon selecting an item in the menu it...
3
by: Guru | last post by:
Hi , I tried the following 4 line of code and answer is what I never expected.I ran the code using C++ compiler(MS-Studio .net 03) also in Unix env.In fact the on Unix i got the correct (or...
4
by: Alfred Taylor | last post by:
I essentially need a countif() function for xsl. Something to where I could do countif(node-set, condition). Rather than try to get too extreme, i decided to just write one for my countif() with...
1
by: Maria | last post by:
Hello! I am new to Crystal reports an I have problems passing parameters form outside to Crystal report an creating a report with data from more than one table This is the problem: I have to...
5
by: Paul | last post by:
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition...
5
by: nass | last post by:
this is a thought experiment. i do not have the time to implement it and test it to see if it works so i am relying on your good will:) thank you in advance im on a linux machine (slackware...
2
by: nitinm | last post by:
hi I want to make a program whose requirement are as following: 1) it has to create an NxN matrix after reading input (i.e. N) from a file in the main() itself. 2) it has to send the array as...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
2
by: richkid | last post by:
Good Day, I'm Trying to pass parameters to represent a column name and value to a stored procedure to execute but havinfg difficulties... can anyone help? declare @columnName...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.