[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

php popup script

I have the following scripts on a php page, which is working correctly:

Drop box script value:
----------------------
onchange="javascript:custpopup(this.value)"

Script called:
-------------------
<SCRIPT language="JavaScript">
<!--
//hide

function custpopup(value)
{
window.open('http://localhost/comwebsites/1callorders/site/cust_find_visit_byname_comment.php?txtName='+ value + '&button2=Find','jav','width=650,height=125,resizable=yes,scrollbars=yes,location=1');
}
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//-->
</SCRIPT>

The value selected in the drop box is passed to the page in the function "custpopup" and brings up the correct data on the referenced php page. I need the popup window to ONLY SHOW ITSELF when  the dataset it is calling has data in a particular field (comment). This dataset is on the referenced php page:

<?php echo $row_comment['comment']; ?>
0
doctorbill
Asked:
doctorbill
  • 4
  • 3
4 Solutions
 
Ray PaseurCommented:
If you only want the pop up window to be available when certain data is present in the PHP script, you might want to test for the presence of that data and only generate the onChange statement if the data is there.  This concept implies some separation of logic from presentation, and that is a good thing.
0
 
doctorbillAuthor Commented:
Can you guide me as to how to do this please ?
0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
Unless you give full html of both pages i cant be sure about the place of codes but this is the behavior
 you need i think.

 
<html>
<head>
<SCRIPT language="JavaScript">
<!--
//hide 

function custpopup(value) { 
    window.open('http://localhost/comwebsites/1callorders/site/cust_find_visit_byname_comment.php?txtName='+ value + '&button2=Find','jav','width=650,height=125,resizable=yes,scrollbars=yes,location=1'); 
}

function MM_popupMsg(msg) { 
    //v1.0
    alert(msg);
}

<?php if(isset($row_comment['comment'])) echo "onload = "MM_popupMsg();";?>
//-->
</SCRIPT>
</head>
<body>
</body>
</html>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
line  16 should be ;

<?php if(isset($row_comment['comment'])) echo "onload = MM_popupMsg();";?>
0
 
doctorbillAuthor Commented:
I will try this solution today but it looks as if the script will give me an alert message if the $row_comment has a value.

What I am after is the popup window ( window.open('http://localhost/comwebsites/1callorders/site/cust_find_visit_byname_comment.php?txtName='+ value + '&button2=Find','jav','width=650,height=125,resizable=yes,scrollbars=yes,location=1'); )
only showing if the $row_comment has a value
0
 
doctorbillAuthor Commented:
Here is my latest code. This works as it should if I enter a value into the '+ value +' field. What I need to be able to do is to create a variable which gets this value from a dropdown box on my page. I have tried using the following:
var value = (document.form2.txtName.value)
This does not work. This is the ONLY thing which is stopping this script from running.
How do I define a variable from a dropbox to be used in the javascript below ?

php Code:
---------------------------------------------
if(isset($row_custCom['comment'])){

echo "<SCRIPT language = JavaScript>
var value = (document.form2.txtName.value)
    window.open('http://localhost/comwebsites/1callorders/site/cust_find_visit_byname_comment.php?txtName='+ value + '&button2=Find','jav','width=650,height=125,resizable=yes,scrollbars=yes,location=1')
      </SCRIPT>";

}
0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
if txtName is the dropdown's name you can get it's value with

var value = document.form2.txtName.options[document.form2.txtName.selectedIndex].value;
0
 
doctorbillAuthor Commented:
didn't completely solve the problem
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now