on my function script i wanted to direct my page into another when it passes my condition. - <script type="text/javascript">
-
-
function show_alert()
-
{
-
if (x > y)
-
{
-
alert ('value is okay');
-
// what code to place here when i want to direct it to the next page?
-
}
-
}
-
</script>
-
-
<form method="post">
-
<input type="submit" onclick="show_alert()" />
-
</form>
you need to do a operation with the values ... - alert ('your are over by: ' + (x-y));
23 1740 gits 5,390
Expert Mod 4TB
you may use: - window.location.href = 'whateverUrl';
kind regards
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.
@acoder
any simple code you can share :)
thanks!
@gits
hi Gits!
this is not working :( this is what i did - if (x>y)
-
{
-
alert (x-y);
-
}
-
else
-
{
-
window.location.href = 'home.php';
-
}
-
-
@acoder
Here what I have in placed -
<form action="home.php" onsubmit="return validate_form()" method="post">
JS - function validate_form()
-
{
-
x= parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value);
-
y = parseInt(document.getElementById('ActualAttendees').value)
-
-
if (x>y)
-
{
-
alert (x-y);
-
}
-
else
-
{
-
window.location.href = 'home.php';
-
}
-
-
}
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
If the x is less than y... I wanted to allow the user to view the page (or html)
gits 5,390
Expert Mod 4TB
then you should return false in the other case ...
gits 5,390
Expert Mod 4TB
put:
after your alert ...
kind regards
gits 5,390
Expert Mod 4TB
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? - if (x>y)
-
{
-
alert ('your are over by:' x-y);
-
return false;
-
}
-
else
-
{
-
alert (x);
-
return true;
-
}
-
gits 5,390
Expert Mod 4TB
you need to do a operation with the values ... - alert ('your are over by: ' + (x-y));
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 -
<form method="post" name="recapform" action="tblevent_entry_recap_handler.php?id=<?php echo $_GET['id'];?> " onsubmit="return show_alert()">
-
header function -
<script type="text/javascript">
-
function show_alert()
-
{
-
entity_alert();
-
-
}
-
</script>
-
sub function -
<script type="text/javascript">
-
function entity_alert()
-
{
-
x= parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
-
+parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
-
+parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
-
+parseInt(document.getElementById('ResidentialFacility').value);
-
-
y = parseInt(document.getElementById('ActualAttendees').value)
-
-
if (x>y)
-
{
-
alert ('Entity is over by:' + (x-y));
-
return false;
-
}
-
else
-
{
-
return true;
-
}
-
-
}
-
</script>
-
In show_alert(), add a return:
It works but when I added more function underneath in only perform the most top functionalities... am i doint this correctly?
header function - <script type="text/javascript">
-
function show_alert()
-
{
-
return entity_alert();
-
return age_alert();
-
-
-
}
-
</script>
sub functions - function entity_alert()
-
{
-
x= parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
-
+parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
-
+parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
-
+parseInt(document.getElementById('ResidentialFacility').value);
-
-
y = parseInt(document.getElementById('ActualAttendees').value)
-
-
if (x>y)
-
{
-
alert ('Entity is over by:' + (x-y));
-
document.getElementById('Organization').focus();
-
return false;
-
}
-
else
-
{
-
return true;
-
}
-
-
}
-
</script>
-
-
-
<!--- 2nd function -->
-
<script type="text/javascript">
-
function age_alert()
-
{
-
tAge= parseInt(document.getElementById('Under18').value)+parseInt(document.getElementById('Eighteen34').value)+parseInt(document.getElementById('ThirtyFive54').value)+parseInt(document.getElementById('FiftyFour').value);
-
-
a = parseInt(document.getElementById('ActualAttendees').value)
-
-
if (tAge>a)
-
{
-
alert ('Age Group is over by:' + (tAge-a));
-
document.getElementById('Under18').focus();
-
return false;
-
}
-
else
-
{
-
return true;
-
}
-
-
}
-
</script>
-
Once you return, it won't execute any more statements.
Try something like: - return (funA() && funB());
@acoder
Here's what I did below but it only performs the first function. Anything do i have to do on sub functions?
Header - <script type="text/javascript">
-
function show_alert()
-
{
-
return (age_alert() && entity_alert());
-
}
-
</script>
sub two functions :
1). - <script type="text/javascript">
-
function entity_alert()
-
{
-
tEntity= parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value)
-
+parseInt(document.getElementById('Education').value)+parseInt(document.getElementById('Medical').value)+parseInt(document.getElementById('Business').value)
-
+parseInt(document.getElementById('Professional').value)+parseInt(document.getElementById('Government').value)+parseInt(document.getElementById('Residential').value)
-
+parseInt(document.getElementById('ResidentialFacility').value);
-
-
y = parseInt(document.getElementById('ActualAttendees').value);
-
-
if (tEntity>y)
-
{
-
alert ('Entity is over by:' + (tEntity-y));
-
return false;
-
}
-
else
-
{
-
return true;
-
}
-
}
-
</script>
2). - <script type="text/javascript">
-
function age_alert()
-
{
-
y = parseInt(document.getElementById('ActualAttendees').value);
-
tAge= parseInt(document.getElementById('Under18').value)+parseInt(document.getElementById('Eighteen34').value)+parseInt(document.getElementById('ThirtyFive54').value)+parseInt(document.getElementById('FiftyFour').value);
-
if (tAge>y) {
-
alert ('Age Group is over by:' + (tAge-y));
-
return false;
-
}
-
-
else {
-
return true;
-
}
-
}
-
</script>
If age_alert() returns false, it won't go to entity_alert() because there's no need.
@acoder
Please tell me what the best way to handle this two conditions before it let the user to go to the next page?
Find a scenario when the first function should return true and the second false to see if it works.
I just redo it and make it simplier and it works perfectly fine. Thanks for all of your inputs ACECODE -
-
if ((a<=y) && (b<=y) && (c <=y) && (d<=y) && (Ustatus=='Complete'))
-
{
-
return true;
-
}
-
else { alert ('Please check your entry total and event status');
-
return false;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)--...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |