Alert box not working with php - javascript

<?php if ($data == "") { ?>
<script type="text/javascript">
alert("review your answer1");
window.location.href = "index1.php";
</script>
<?php } else { ?>
<script type="text/javascript">
alert("review your answer2");
window.location.href = "index2.php";
</script>
<?php } ?>
Alert box is not showing in above code as well as page is also not redirecting.
What is wrong in it?

Do the other way around:
<script>
var data = <?php echo $data; ?>
if ( data === "" ) {
alert("review your answer1");
window.location.href = "index1.php";
} else {
alert("review your answer2");
window.location.href = "index2.php";
}
</script>

Improving your code, it may require some adaptation:
<script>
alert("review your answer<?echo $data;?>");
window.location.href = "index<?echo $data;?>.php";
</script>

Related

Display alert message and redirect the page

I have the following code. On failure i need to get the alert Already exists and redirect to te registration page. But on success i need to check the session and based on the role id i need to redirect the page but the alert and redirection is not happening in this case ... can you please tell where i am wrong
if ($referral_patient_id != NULL) {
echo "<script language='javascript'>
alert('Successfully Added');
if ($_SESSION['role_id'] != 6) {
echo 'window.location.href="../Laboratory_Home"';
} else {
echo 'window.location.href="../Billing_Home"';
} </script>";
} else {
echo "<script language='javascript'>
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
</script>";
}
<?php if ($referral_patient_id != NULL) { ?>
<script type='javascript'>
alert('Successfully Added');
<?php if ($_SESSION['role_id'] != 6) { ?>
window.location.href="../Laboratory_Home";
<?php } else { ?>
window.location.href="../Billing_Home";
<?php } ?>
</script>
<?php }else { ?>
<script type='javascript'>
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
</script>
<?php } ?>
Try this one dude.
Try this javascript code :
<script language='javascript'>
var referral_patient_id = '<?php echo $referral_patient_id; ?>';
if(referral_patient_id != null)
{
alert('Successfully Added');
var role_id = '<?php echo $_SESSION["role_id"]; ?>';
if (role_id != '6') {
window.location.href="../Laboratory_Home";
} else {
window.location.href="../Billing_Home";
}
}
else
{
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
}
</script>
You have mixed content. PHP and Javascript. Try this one
echo "<script language='javascript'>
alert('Successfully Added');
</script>";
if($_SESSION['role_id']!=6){
echo "<script language='javascript'>window.location.href='../Laboratory_Home'</script>";
} else {
echo "<script language='javascript'>window.location.href='../Billing_Home'</script>";
}
Or this one
echo "<script language='javascript'>
alert('Successfully Added');
if( ".$_SESSION['role_id']." !=6) {
window.location.href='../Laboratory_Home';
} else {
window.location.href='../Billing_Home';
}
</script>";

How to change color code in a script

Hi guys i want to change this line
$("#Tcounter").css("color","red");
in this script with a color code #BC0202, how do i need to do this?
<script type="text/javascript">
$(document).ready(function() {
var Tcharacters = <?php echo $max_character_length_title; ?>;
$("#Tcounter").append("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+ Tcharacters+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
$("#title<?php echo osc_current_user_locale(); ?>").keyup(function(){
if($(this).val().length > Tcharacters){
$(this).val($(this).val().substr(0, Tcharacters));
}
var Tremaining = Tcharacters - $(this).val().length;
$("#Tcounter").html("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+ Tremaining+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
if(Tremaining <= 10)
{
$("#Tcounter").css("color","red");
}
else
{
$("#Tcounter").css("color","black");
}
});
var Dcharacters = <?php echo $max_character_length_description; ?>;
$("#Dcounter").append("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+ Dcharacters+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
$("#description<?php echo osc_current_user_locale(); ?>").keyup(function(){
if($(this).val().length > Dcharacters){
$(this).val($(this).val().substr(0, Dcharacters));
}
var Dremaining = Dcharacters - $(this).val().length;
$("#Dcounter").html("<small><?php osc_esc_js(_e('You have','ctg_housing')); ?> <strong>"+ Dremaining+"</strong> <?php osc_esc_js(_e('characters remaining','ctg_housing')); ?></small>");
if(Dremaining <= 10)
{
$("#Dcounter").css("color","red");
}
else
{
$("#Dcounter").css("color","black");
}
});
});
</script>
More information about this i cant give!
Thanks
Simple, change red to #BC0202
$("#Tcounter").css("color","#BC0202");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="Tcounter">Foobar</div>
Just Replace color name with corresponding hex code of that of color.

PHP file upload - Not checking the file size

I'm trying to make a file upload form from two days but cant seem to get this to work. My code is checking the extension of the file but not checking the file size. I googled, tried different methods but unable to get this to work. Can someone help?
Here's the code -
<?php
if(isset($_POST['carsubmit']))
{
foreach($_POST as $key=>$val)
${$key}=addslashes($val);
$allowed_filetypes = array('.jpg','.gif','.bmp','.png');
$max_filesize = 2097152;
$upload_path = "resumes/";
$filename = $_FILES['attachresume']['name'];
$file_tmp =$_FILES['attachresume']['tmp_name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
$cardupcheck = "select * from `careers` where `email` = '$email'";
$cardupresult = mysql_query($cardupcheck);
if(mysql_num_rows($cardupresult)==1)
{
?>
<script type="text/javascript">
notification('You have already sent us!','error');
</script>
<?php
}
else
{
if(!in_array($ext,$allowed_filetypes)){
?>
<script type="text/javascript">
notification('Please check the file extension. Only jpg, png and gif are allowed!','error');
</script>
<?php
}
else if($file_tmp > $max_filesize){
?>
<script type="text/javascript">
notification('too large!','error');
</script>
<?php
}
else
{
move_uploaded_file($file_tmp,"resumes/".$filename);
$carquery = "INSERT INTO `careers` (`name`, `email`, `phone`, `aoi`, `qual`, `resume`) VALUES ('$name', '$email', '$phone', '$aoi', '$qual', '$filename')";
$carresult = mysql_query($carquery);
if($carresult)
{
?>
<script type="text/javascript">
notification('Thank you! We will get back to you soon!','success');
</script>
<?php
}
else
{
?>
<script type="text/javascript">
notification('There was an error. Please try after some time!','error');
</script>
<?php
}
}
}
}
?>
You are comparing file size with the file name. Get the size of the uploaded file by $_FILES["attachresume"]["size"].Use this code instead
<?php
if(isset($_POST['carsubmit']))
{
foreach($_POST as $key=>$val)
${$key}=addslashes($val);
$allowed_filetypes = array('.jpg','.gif','.bmp','.png');
$max_filesize = 2097152;
$upload_path = "resumes/";
$filename = $_FILES['attachresume']['name'];
$file_tmp =$_FILES['attachresume']['tmp_name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
$file_size = $_FILES["attachresume"]["size"]; // Here is the size of the uploaded file
$cardupcheck = "select * from `careers` where `email` = '$email'";
$cardupresult = mysql_query($cardupcheck);
if(mysql_num_rows($cardupresult)==1)
{
?>
<script type="text/javascript">
notification('You have already sent us!','error');
</script>
<?php
}
else
{
if(!in_array($ext,$allowed_filetypes)){
?>
<script type="text/javascript">
notification('Please check the file extension. Only jpg, png and gif are allowed!','error');
</script>
<?php
}
else if($file_size > $max_filesize){
?>
<script type="text/javascript">
notification('too large!','error');
</script>
<?php
}
else
{
move_uploaded_file($file_tmp,"resumes/".$filename);
$carquery = "INSERT INTO `careers` (`name`, `email`, `phone`, `aoi`, `qual`, `resume`) VALUES ('$name', '$email', '$phone', '$aoi', '$qual', '$filename')";
$carresult = mysql_query($carquery);
if($carresult)
{
?>
<script type="text/javascript">
notification('Thank you! We will get back to you soon!','success');
</script>
<?php
}
else
{
?>
<script type="text/javascript">
notification('There was an error. Please try after some time!','error');
</script>
<?php
}
}
}
}
?>
Hope this helps you
This one worked -
else if(($_FILES['attachresume']['size'] >= $max_filesize) || ($_FILES["attachresume"]["size"] == 0))

jquery script dosen't works in safari

I got problem with jquery code.It somehow doesn't work in safari browser. Rest of the browsers working fine but in safari I dont know why not any solution?
Index.php - I have this code inside HEAD
<script type="text/javascript">
$(document).ready(function () {
var prilohy = <? php echo json_encode($linkpar); ?> ;
if (prilohy == "Pizza") {
$('#content_donaska_extra').show();
} else if (prilohy == null) {
$('#content_donaska_extra').show();
} else {
$('#content_donaska_extra').hide();
}
});
</script>
Remove the space between <? and php
var prilohy = <?php echo json_encode($linkpar); ?> ;
script be
$(document).ready(function () {
var prilohy = <?php echo json_encode($linkpar); ?> ;
if (prilohy == "Pizza" || prilohy == null) {
$('#content_donaska_extra').show();
} else {
$('#content_donaska_extra').hide();
}
});

echo php javascript alert?

How can I echo this javascript if the php error messages is called? I have an error message setting that when a user misses his username or password it triggers an error message. The php error message is called by a php code. Here is the code:
<?php echo showmessage($msg) ?>
I have an alert message in javascript that when called it will make a javascript css pop up alert box. IF the javascript code is present it will show the alert box right away after reload. Here is code:
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
})
</script>
How can I incorporate so that when the php echo message comes up it will trigger the javscript alert message. I was trying an if in php, so something like this code:
if ( showmessage($msg) ) {
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
})
</script>
}
How can I echo my javascript message on the php call?
This could be written like this:
endif
endif-stackoverflow
<?php if (showmessage($msg)): ?>
<script>
$(document).ready(function (){
jqxAlert.alert('Alert Message');
});
</script>
<?php endif; ?>
Or like this:
<?php if (showmessage($msg)) { ?>
<script>
$(document).ready(function (){
jqxAlert.alert('Alert Message');
});
</script>
<?php } ?>
Or like this:
<?php
if (showmessage($msg)) {
echo
'
<script>
$(document).ready(function (){
jqxAlert.alert(\'Alert Message\');
});
</script>
';
}
?>
short tags
short hand comparison (ternary)
ternary 2
Or even this (probably not the best idea though):
<?= (showmessage($msg)) ? '<script>$(document).ready(function (){jqxAlert.alert(\'Alert Message\');});</script>' : ""; ?>
Alternatively, if you mean you would like to put the error message in that alertbox
<?php
if (showmessage($msg)) {
echo
'
<script>
$(document).ready(function (){
jqxAlert.alert('.showmessage($msg).');
});
</script>
';
}
?>
and again in the first style:
<?php if (showmessage($msg)): ?>
<script>
$(document).ready(function (){
jqxAlert.alert(<?= showmessage($msg) ?>);
});
</script>
<?php endif; ?>
something like this.. close your php tag before starting to write javascript..
<?php if ( showmessage($msg) ) { ?>
<script type="text/javascript">
alert('Alert Message');
</script>
<?php } ?>
Can you try this
<?PHP if ( showmessage($msg) ) { ?>
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
});
</script>
<?PHP } ?>

Categories

Resources