472,985 Members | 2,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

can't call JavaScript function from php

A have a php scrip where I call a JavaScript function. I don't know why, but it doesn't work. At the beginning, when I was writing the script it was working but now it's not. I don't know wхat to do. Please help me. Here is the php code:
Expand|Select|Wrap|Line Numbers
  1.     function print_rezBilet($rezBilet,$posRezBilet1){
  2.         $step=$_SESSION['cekor'];
  3.         $max=$_SESSION['max'];
  4.         $curr= $_SESSION['currentRezBilet']+$step-1 ;
  5.  
  6.  
  7.         if($max<$curr)
  8.             $curr=$max;
  9.  
  10.         //vo ovie dve promenlivi se zacuvuva brojot na prikazanata strana i
  11.         //vkupniot broj na strani
  12.         $currPage=ceil($curr / $_SESSION['cekor']);
  13.         $maxPage=ceil($max / $_SESSION['cekor']);
  14.         if (!$rezBilet) {
  15.             echo error_message('Не се внесени резервации на билети');
  16.             echo <<<END
  17.             <tr><form method="post" action="$posRezBilet1" ><td align="center">
  18.             <center>
  19.             <input type="submit" value="Додади нов резервација" name="newRezBilet" class="button">
  20.             </center>
  21.         </td>
  22.         </form>
  23.         </tr>
  24. END;
  25.         }
  26.         else {
  27.             echo <<<END
  28.             <center><table cellpadding='2' cellspacing='1' bordercolor='#993300'>
  29.             <tr>
  30.             <th scope='col'>Измени</th>
  31.             <th scope='col'>Бриши</th>
  32.             <th scope='col'>ТуристID<a href="?orderColumnRezBilet=turist_id&orderRezBilet=desc"/><img src="../images/dole.gif" width="10" height="10" border="0"/></a><a href="?orderColumnRezBilet=turist_id&orderRezBilet=asc"/><img src="../images/gore.gif" width="10" height="10" border="0"/></a></th>
  33.                 <th scope='col'>БилетId<a href="?orderColumnRezBilet=b_id&orderRezBilet=desc"/><img src="../images/dole.gif" width="10" height="10" border="0"/></a><a href="?orderColumnRezBilet=b_id&orderRezBilet=asc"/><img src="../images/gore.gif" width="10" height="10" border="0"/></a></th>
  34.             <th scope='col'>Дата на резервирање <a href="?orderColumnRezBilet=rez_data&orderRezBilet=desc"/><img src="../images/dole.gif" width="10" height="10" border="0"/></a><a href="?orderColumnRezBilet=rez_data&orderRezBilet=asc"/><img src="../images/gore.gif" width="10" height="10" border="0"/></a></th>
  35.             <th scope='col'>Количина<a href="?orderColumnRezBilet=kolicina&orderRezBilet=desc"/><img src="../images/dole.gif" width="10" height="10" border="0"/></a><a href="?orderColumnRezBilet=kolicina&orderRezBilet=asc"/><img src="../images/gore.gif" width="10" height="10" border="0"/></a></th>
  36.             </tr>
  37.  
  38. END;
  39.         $poraka="Dali sakas";
  40.         foreach($rezBilet as $rezB)
  41.         {
  42.             echo '<tr>';
  43.             echo '<td  align="center"><a href="?modifyRezBilet='.
  44. htmlentities($rezB['TURIST_ID'])." ".htmlentities($rezB['B_ID']).'" /><img src="../images/edit.png"  width="24" height="24" border="0" /></a></td>';
  45.             echo '<td align="center"><a href="?deleteRezBilet='.
  46. htmlentities($rezB['TURIST_ID'])." ".htmlentities($rezB['B_ID']).'" /><img src="../images/delete2.png" width="24" height="24" border="0"  /></a></td>';
  47.             echo '<td>'.$rezB['TURIST_ID'].'<a  href="?showTur='.
  48. htmlentities($rezB['TURIST_ID']).'" onclick="showListTurist();return false;" /><img align="right" src="../images/details.png" width="14" height="14" border="0"  /></a></td>';
  49.             echo '<td>'.$rezB['B_ID'].'<a  href="?showBil='.
  50. htmlentities($rezB['B_ID']).'" onclick="showListBilet(); return false;" /><img  align="right" src="../images/details.png" width="14" height="14" border="0"  /></a></td>';
  51.             echo '<td>'.$rezB['REZ_DATA'].'</td>';
  52.             echo '<td>'.$rezB['KOLICINA'].'</td>';
  53.             echo '</tr>';
  54.         }
  55.         echo <<<END
  56.         <tr><form method="post" action="$posRezBilet1"><td align="center">
  57.         <a href="?newRezBilet2=vnesi" /><img src="../images/user1_add.png"  width="36" height="36" border="0" /></a></td><td colspan="1" align="center">
  58.         <input type="submit" value="Додади нова резервација" name="newRezBilet" class="button">
  59.         </td>
  60.  
  61.         <td colspan="2"><div align="center">
  62.         <input type="submit" value="< Претходни $step" name="previousRezBilet" class="button">
  63.         <input type="submit" value="Следни $step >" name="nextRezBilet" class="button">
  64.         </div>
  65.         </td>
  66.         <td>
  67.         <select name="cekor" style="background:#F1D798" onchange="MM_jumpMenu('parent',this,0)">
  68.             <option value="" style="background:#F1D798">прикажи</option>
  69.             <option value="?cekor=5" style="background:#F1D798">5</option>
  70.             <option value="?cekor=10" style="background:#F1D798">10</option>
  71.             <option value="?cekor=15" style="background:#F1D798">15</option>
  72.             <option value="?cekor=20" style="background:#F1D798">20</option>
  73.             <option value="?cekor=25" style="background:#F1D798">25</option>
  74.             <option value="?cekor=30" style="background:#F1D798">30</option>
  75.          </select>
  76.         </td>
  77.         <td align="center">$currPage/$maxPage Страна</td>
  78.         </tr>
  79.         </form>
  80.         </table></center>
  81. END;
  82.     }
  83. }
  84.  


and here is the part where the JavaScript functions are:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. <!--
  3. function MM_jumpMenu(targ,selObj,restore){ //v3.0
  4.   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  5.   if (restore) selObj.selectedIndex=0;
  6. }
  7. function MM_popupMsg(msg) { //v1.0
  8.   confirm(msg);
  9. }
  10. //-->
  11. </script>
  12. <!-- TinyMCE -->
  13. <script language="javascript" type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
  14. <script language="javascript" type="text/javascript">
  15.     tinyMCE.init({
  16.         mode : "textareas",
  17.         theme : "simple"    
  18.     });
  19.  
  20.     function fileBrowserCallBack(field_name, url, type, win) {
  21.         // This is where you insert your custom filebrowser logic
  22.         alert("Filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);
  23.  
  24.         // Insert new URL, this would normaly be done in a popup
  25.         win.document.forms[0].elements[field_name].value = "someurl.htm";
  26.     }
  27.  
  28.     function showListTurist() 
  29.     {
  30.         <?php
  31.             $_SESSION['showTur']=$_GET['showTur'];
  32.         ?>
  33.         sList = window.open("turist_prozorecB.php", "turist", "width=800,height=200, scrollbars=yes");
  34.     }
  35.  
  36.     function showListBilet() 
  37.     {
  38.         <?php
  39.             $_SESSION['showBil']=$_GET['showBil'];
  40.             echo "neso";
  41.         ?>
  42.         sList = window.open("bilet_prozorecB.php", "bilet", "width=800,height=100, scrollbars=1");
  43.     }
  44.  
  45.     function showListTurInsert()
  46.     {
  47.         sList = window.open("turist_prozorecList.php", "turisti", "width=800,height=700, scrollbars=1");
  48.     }
  49.         function showListBilInsert()
  50.     {
  51.         sList = window.open("bilet_prozorecList.php", "bileti", "width=800,height=700, scrollbars=1");
  52.     }
  53.  
  54.  
  55.  
  56. </script>
  57. <!-- /TinyMCE -->
  58.  
I call the functions on other places too, but it doesn't work there neither :
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td colspan=3 align="right">
  3.         Турист:
  4.         <input type="text" name="turistid" size="29" value=$turistid>
  5.         <input type="button" value="излистај" onClick="showListTurInsert()" class="button">
  6.     </td>
  7. </tr>
  8.  
PLEASE HELP ME
Aug 21 '07 #1
10 7254
Atli
5,058 Expert 4TB
Please post your code inside [code] tags! It's impossible to read it without them.

What have you changed since the code worked?
Are you getting any PHP or JavaScript errors?
What is your code supposed to be doing? How is it not working?
Aug 22 '07 #2
jx2
228 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. <a  href="?showTur='.htmlentities($rezB['TURIST_ID']).' 
i'm not sure but i think it won't work
shouldnt that be urlencode() as it is part of a url?

regards
jx2
Aug 22 '07 #3
here is the code in code tags
[PHP]$poraka="Dali sakas";
foreach($rezBilet as $rezB)
{
echo '<tr>';
echo '<td align="center"><a href="?modifyRezBilet='.
htmlentities($rezB['TURIST_ID'])." ".htmlentities($rezB['B_ID']).'" /><img src="../images/edit.png" width="24" height="24" border="0" /></a></td>';
echo '<td align="center"><a href="?deleteRezBilet='.
htmlentities($rezB['TURIST_ID'])." ".htmlentities($rezB['B_ID']).'" /><img src="../images/delete2.png" width="24" height="24" border="0" /></a></td>';
echo '<td>'.$rezB['TURIST_ID'].'<a href="?showTur='.
htmlentities($rezB['TURIST_ID']).'" onclick="showListTurist();return false;" /><img align="right" src="../images/details.png" width="14" height="14" border="0" /></a></td>';
echo '<td>'.$rezB['B_ID'].'<a href="?showBil='.
htmlentities($rezB['B_ID']).'" onclick="showListBilet(); return false;" /><img align="right" src="../images/details.png" width="14" height="14" border="0" /></a></td>';
echo '<td>'.$rezB['REZ_DATA'].'</td>';
echo '<td>'.$rezB['KOLICINA'].'</td>';
echo '</tr>';
}
echo <<<END
<tr><form method="post" action="$posRezBilet1"><td align="center">
<a href="?newRezBilet2=vnesi" /><img src="../images/user1_add.png" width="36" height="36" border="0" /></a></td><td colspan="1" align="center">
<input type="submit" value="Додади нова резервација" name="newRezBilet" class="button">
</td>

<td colspan="2"><div align="center">
<input type="submit" value="< Претходни $step" name="previousRezBilet" class="button">
<input type="submit" value="Следни $step >" name="nextRezBilet" class="button">
</div>
</td>
<td>
<select name="cekor" style="background:#F1D798" onchange="MM_jumpMenu('parent',this,0)">
<option value="" style="background:#F1D798">прикажи</option>
<option value="?cekor=5" style="background:#F1D798">5</option>
<option value="?cekor=10" style="background:#F1D798">10</option>
<option value="?cekor=15" style="background:#F1D798">15</option>
<option value="?cekor=20" style="background:#F1D798">20</option>
<option value="?cekor=25" style="background:#F1D798">25</option>
<option value="?cekor=30" style="background:#F1D798">30</option>
</select>
</td>
<td align="center">$currPage/$maxPage Страна</td>
</tr>
</form>
</table></center>
END;
}
} [/PHP]

this is only the part where I call the functions, and here are the JavaScript functions

Expand|Select|Wrap|Line Numbers
  1. function showListTurist() 
  2.     {
  3.         <?php
  4.             $_SESSION['showTur']=$_GET['showTur'];
  5.         ?>
  6.         sList = window.open("turist_prozorecB.php", "turist", "width=800,height=200, scrollbars=yes");
  7.     }
  8.  
  9.     function showListBilet() 
  10.     {
  11.         <?php
  12.             $_SESSION['showBil']=$_GET['showBil'];
  13.             echo "neso";
  14.         ?>
  15.         sList = window.open("bilet_prozorecB.php", "bilet", "width=800,height=100, scrollbars=1");
  16.     }
The code prints the values stored the array $rezBilet in a table and I want when you press on the picture 'details' to open new window. That's why I call the JavaScript function. But I also want to send the variable $rezB['TURIST_ID'] to the new window that opens, so thats why I use href=?showTur..., and then in the JavaScript function I put it in session.
I don't get any kind of errors, it does nothing, and the biggest problem is, that I that I haven't changed much. I only added some things but on the other part of the script that has not much connection whit this (I think). It just stop working.
Just adds the value from $rezB['TURIST_ID'] to showTur, but it doesn't call the JavaScript functions.
Sorry that I didn't write correctly the previous post, but I'm new at this.
Aug 22 '07 #4
jx2
228 100+
you should use [ php] [ /php] tags for your code

what do you mean do not call javascript? php cant call javascript anyway...

regards jx2
Aug 22 '07 #5
pbmods
5,821 Expert 4TB
Heya, evicailieva. Welcome to TSDN!

You're having trouble because (as JX2 mentioned) PHP can't call a JavaScript function.

PHP is server-side, whereas JavaScript is client-side. Since the code is running on separate machines, there's no way for them to directly communicate.

Now, you can have the PHP output JavaScript that you'd like the browser to run while it's loading the page, and you can use AJAX to send a new HTTP request to the server to run additional scripts after the main page has loaded, but those are your best options.
Aug 22 '07 #6
I mean it does not execute the code in the function showListTurist(), it doesn't open new window.
Aug 22 '07 #7
pbmods
5,821 Expert 4TB
Heya, Evicailieva.

You mean that when you click on the links in the table cells, it's not opening the new window, correct?

Are you getting an error, or is it just not doing anything?
Aug 22 '07 #8
Yes that's exactly what I mean. It does not show errors. It does nothing. I really don't know what's wrong! I also have this code

[PHP]echo <<<END
<tr>
<td colspan=3 align="right">
Турист:
<input type="text" name="turistid" size="34" value="турист">
<input type="button" value="излистај" onClick="showListTurInsert()" class="button">
</td>
</tr>
END;[/PHP]

and also dosen't open new window. It also does nothing.
Aug 22 '07 #9
Atli
5,058 Expert 4TB
...
The code prints the values stored the array $rezBilet in a table and I want when you press on the picture 'details' to open new window. That's why I call the JavaScript function. But I also want to send the variable $rezB['TURIST_ID'] to the new window that opens, so thats why I use href=?showTur..., and then in the JavaScript function I put it in session
....
There is one more thing I think may be causing a problem.

You call a JavaScript function through the onclick event in a <a> tag, but it the same tag you set the href parameter, trying to pass the url in the href parameter to the window, opened by you JavaScript function.
This will not work. What actually happens is, when your user clicks the <a> link, the JavaScript function is executed, and then the client is redirected to the URL in the href parameter

For example:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function alertme() 
  3. {
  4.     alert("You have been alerted!");
  5. }
  6. </script>
  7.  
  8. <a href="?var=val" onclick="alertme();">Linkage</a>
  9.  
This will put up an alert box and then it will redirect you to '?var=val'.

You would need to do something like this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function openWindow(getParams) 
  3. {
  4.     window.open("mypage.php?"+ getParams);
  5. }
  6. </script>
  7.  
  8. <a href="#" onclick="openWindow('var=val');">Linkage</a>
  9.  
Which will open up another window showing the page 'mypage.php?var=val'.
Aug 22 '07 #10
Thank you very much. That works.
Aug 22 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: David Shorthouse | last post by:
Hey folks, Not an off-topic posting.....since I was shot-down in an earlier post...this one's legit. How do I go about calling a server-side vbscript within a client-side javascript function?...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
4
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
7
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.