Jump to content

Problem regarding Posting of a function to two places at the same time


kalcee

Recommended Posts

Hello people,

 

I am kinda newbie to PHP and I have done a little bit of reading before starting my present project. So, please bear with me if there are any technical mistakes in my post. That said, here is my problem.

 

My project is to develop a webpage which has 2 frames in it. One has the google maps in it and the other has information regarding each point in it. In this part I have wrote a form which searches for all the results with a given searchword and I named it as keyword. Here is the code for that.

 

<form name=queryform method=get action="List.php" target="_self">

  <table>

    <tr valign=center>

      <td><input type="text" name="keyword" size="20"></td>

      <td><img src = "images/SEARCH.gif"

            width = 49

            height = 18

            border = 0

            class = "mouseBeOffMe"

            onmouseover = "this.className='mouseBeOnMe'"

            onmousedown = "this.className='mouseBeDown'"

            onmouseup = "this.className='mouseBeUp'; document.queryform.submit();" 

            onmouseout  = "this.className='mouseBeOffMe'"></td>

      <td><img src = "images/RESET2.gif"

            width = 45

            height = 18

            border = 0

            class = "mouseBeOffMe"

            onmouseover = "this.className='mouseBeOnMe'"

            onmousedown = "this.className='mouseBeDown'"

            onmouseup = "this.className='mouseBeUp'; document.queryform.reset();" 

            onmouseout  = "this.className='mouseBeOffMe'"></td>

    </tr>

  </table>

  <input type="hidden" name="Layer" value="<? echo $Layer; ?>">

  <input type="hidden" name="MapScale" value="<? echo $MapScale; ?>">

  <input type="hidden" name="MapLat" value="<? echo $MapLat; ?>">

  <input type="hidden" name="MapLng" value="<? echo $MapLng; ?>">

</form>

 

As soon as the button is clicked, this part of page re directs to a new page called List.php which displays all the searched results. My new task is to make the other half of page to display the exact same points in the google maps. So, I wrote some queries to pull up the searched results as points and made that a function called DataSearch() in the same page called Map.php.

 

Now here comes the problem. As soon as I click the search button both of them should be implemented at the same time. But I don't know how to call the Datasearch function in Map.php as the key word is already getting posted to List.php. If some one could shed some light on how to post the form to two different places, I would be really thankful to them.

 

Hope I am clear on presenting my problem. Any help appreciated.

Thanks in advance

Link to comment
Share on other sites

Not sure i follow the problem entirely, but you cannot have two actions for a form. However, if you're using frames you could do something like:

 

1.) Submit the form in frame 1 - this loads list.php (i believe)

2.) In list.php, include some javascript to reload frame 2 - reload the frame with the information that map.php needs in the url.

 

p.s. Welcome to the forum. Since you're new, i wont berate you for not enclosing your code in


tags :P

Link to comment
Share on other sites

Hi Ben,

 

I have wrote a java script to reload the frame 2. It is reloading well, but how do I reload it such that it performs the function DataSearch() in the Map.php page.

 

Here is the simple code I wrote to reload the frame

 

<script language="javascript" type="text/javascript">
window.parent.themap.location.reload();
</script>

 

"themap" is the name of the frame which is being reloaded.

Link to comment
Share on other sites

What i was meaning was changing the location to map.php?whatever:

 

<script language="javascript" type="text/javascript">
window.parent.themap.location = "Map.php?action=datasearch;
</script>

 

You could then obviously add any other variables that you need in Map.php to the URL too.

 

In Map.php you'll then need to check the value of $_GET['action'] - if it's set and it equals datasearch, run the function.

Link to comment
Share on other sites

As said earlier, being a newbie to PHP i couldnt exactly follow what you are trying to say. Sorry about that. Instead i tried this in the frame 1 containing List.php.

 

<script language="javascript" type="text/javascript">
window.top.themap.DataSearch();
</script>

 

This is performing the DataSearch() function well. This function has a couple of SQL queries that use the search word($keyword) that is being used to get List.php.

 

So from that frame, I tried to pass the variable Keyword using GET.

<form method="get" action="Map.php"><br/>
<input type="hidden" name="keyword" /><br/>
</form>

 

(the input type is given as hidden cuz it has already been taken and is being used to generate the List.php.) My problem is that the variable is not being passed into Map.php even though I gave

$keyword= $_GET['keyword']; 

in the Map.php page. I am clue less on where I am making the mistake.

Link to comment
Share on other sites

Hmm, perhaps we've been getting our wires crossed a bit.

 

DataSearch() is a javascript function?

 

If that's the case, couldn't you just pass the variable you need as a parameter?

 

E.g.

<script language="javascript" type="text/javascript">
window.top.themap.DataSearch('keyword');
</script>

Link to comment
Share on other sites

Sure.. here is the code for the DataSearch function.

 

function DataSearch() 
    {
        //remove the existing points
        map.clearOverlays();
<?


// Create a point at each unique location...
     $q1="SELECT distinct LOCATION,IMPACTAREA,LONGITUDE,LATITUDE FROM aictest WHERE PROGTITLE like '%$keyword%' or LOCATION like '%$keyword%' or PROGADDR like '%$keyword%' or CITY like '%$keyword%' or STATE like '%$keyword%' or ZIP like '%$keyword%'" ;
 $r1 = mssql_query($q1);
 $n1 = mssql_num_rows($r1);
 	$i=0;
           while ($i<$n1) :
	   $LOCATION=mssql_result($r1,$i,"LOCATION");
           $LATITUDE=mssql_result($r1,$i,"LATITUDE");
           $LONGITUDE=mssql_result($r1,$i,"LONGITUDE");
	   $IMPACTAREA=mssql_result($r1,$i,"IMPACTAREA");
	  echo "var point = new GLatLng($LATITUDE, $LONGITUDE);\n"; 
	  
	  
                  // Create a link for each program at that unique location...

                     $q2 = "SELECT PROGTITLE, PROGURL FROM aictest WHERE LOCATION = '$LOCATION' and (PROGTITLE like '%$keyword%' or LOCATION like '%$keyword%' or PROGADDR like '%$keyword%' or CITY like '%$keyword%' or STATE like '%$keyword%' or ZIP like '%$keyword%') ORDER BY IMPACTAREA, PROGTITLE";
	  
                  $r2 = mssql_query($q2);
                  $n2 = mssql_num_rows($r2);
			  
			   if($n2>10) :	// Create a link to the Lister program and target the data frame...
	     $htm = "<font face=Arial size=1 color=#91002F>There are $n2 search programs at this location.</font><br>";
                     $htm .= "<a href=\"AicprogsLister.php?Layer=$Layer&LOCATION=$LOCATION\" target=\"data\"><font face=Arial size=1>Click here for the program list.</font></a><br>";


else:	// Build a list of links in the info ballon...
                     $j=0;
                     $htm="";
                     while ($j<$n2) :
                        
                         $PROGTITLE=mssql_result($r2,$j,"PROGTITLE");
					 $PROGURL=mssql_result($r2, $j,"PROGURL");
                         $htm .= "<a href=\"$PROGURL\" target=\"_blank\"><font face=Arial size=1>$PROGTITLE</font></a><br>";
                         $j++;
                     endwhile;  
				 endif;

	    echo " var marker = createMarker(point, '$htm', '$IMPACTAREA');\n";
                  echo "         map.addOverlay(marker);\n";
                  echo "\n";
                  $i++;
           endwhile;
	   ?>
     }

//end DataSearch

 

I somehow need to pass the variable $keyword. If i replace that with any other search word in this page myself, its working fine and showing up the points. But I want the user to enter the word in frame 1 and get that passed it into here

Link to comment
Share on other sites

Ok, well in that case, DataSearch IS a javascript function - it's just that most of the function comes from the output of the PHP code. However, the keywords are required by the PHP, so we cannot just pass the keyword to the javascript function.

 

Now, i think the solution will be going back to what i said right at the beginning - you need to change the location of the frame and include the keyword in the url. So, the javscript for that would be:

 

<script language="javascript" type="text/javascript">
window.parent.themap.location = "Map.php?action=datasearch&keyword=yourkeywordhere;
</script>

 

Then, you would use this in map.php:

 

if(isset($_GET['action']){//action i set - dont need to check its value since its not being used for anything else
    $keyword = $_GET['keyword'];//since this is being used in the query, you'll need to validate this too
}

Link to comment
Share on other sites

Thanks for your immense help. But it still some how doesnt work. I added the endif; at the end just in case to see if that was the reason. But still the same..

 

if($action != "Reset") :
    $keyword = $_GET['keyword'];

endif;

 

does this code has the same functionality as the one u gave? Cuz this way the variable is returning its value to Map.php, but that is causing some serious trouble as none of my other functionalities arent working.

Link to comment
Share on other sites

After all this discussion I just found that my problem is that I am unable to pass a variable to a certain function which is in a different frame.

 

Could some one throw some light if what I am assuming is right ? And any fix to my problem ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.