Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  73] [ 1]  / answers: 1 / hits: 46541  / 11 Years ago, sat, september 28, 2013, 12:00:00

Scenario:



I created a filtering using IF ELSE where when the user click BOX A AND BOX B... Then assuming the BOX A is already full, after the user hit the SAVE BUTTON, a confirmation message will display saying that... The Box you chosen is already full. Do you want to save the other items?



Here's my Code:



<?php
//else if......
else if($box== BOX A && $row[item] == 100)
{

echo <script type='text/javascript'>;
echo var r=confirm('The Box you chosen is already full. Do you want to save the other items?');
echo if (r==true){;
echo alert('You pressed OK!')};
echo else{;
echo alert('You pressed Cancel!')};
echo </script>;

}
?>


I have a problem with the code and when I try to trace it using echo enter here;
its always stop after the program read this code



  echo <script type='text/javascript'>;


Then it will jump it in here:



 echo </script>;


RESULT:



its not displaying the pop up message ... So all I need is to display the pop up message and I dont know why, why its not displaying... There is no button involve for the displaying of confirmation message...It will just pass by in if else and then it will prompt up if the user wants to continue the saving if one of the box is already full if not he/she will press the cancel...



NOTE:
I'm only a beginner for PHP and Javascript..



Thank you in advance.


More From » php

 Answers
261

This is because you start a new <? / <?php tag inside another



else if($box== BOX A && $row[item]  == 100)
{
<?php
echo <script type='text/javascript'>;
echo var r=confirm('The Box you chosen is already full. Do you want to save the other items?');
echo if (r==true){;
echo alert('You pressed OK!')};
echo else{;
echo alert('You pressed Cancel!')};
echo </script>;
?>
}


should be



else if($box== BOX A && $row[item]  == 100)
{
echo <script type='text/javascript'>;
echo var r=confirm('The Box you chosen is already full. Do you want to save the other items?');
echo if (r==true){;
echo alert('You pressed OK!')};
echo else{;
echo alert('You pressed Cancel!')};
echo </script>;
}


But personally I think



    else if($box== BOX A && $row[item]  == 100)
{
?>
<script>
var r=confirm('The Box you chosen is already full. Do you want to save the other items?');
if (r==true) {
alert('You pressed OK!');
} else {
alert('You pressed Cancel!');
}
</script>
<?
}


is much cleaner and more readable. Keep javascript out of PHP, dont echo it out, if you can avoid it. It can be hard to survey in 6 months.


[#75366] Friday, September 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;