Reply
Where to put javascript function
Old 05-04-2006, 07:00 AM Where to put javascript function
Super Talker

Posts: 145
Hello,

I would appreciate if you could help me with the question I have.

I have created an external javascript(calculate.js) that has a function called calculate and this function calculates a price
depending on the dates the user select.
What I am trying to do now is to run this method in an php page and its result to display it in a table like the example:

<table>
<tr>
<td>calculate(1,2,2,0)</td>
<tr>
</table>

I have put in the head tag the code where is the javascript
<script language="javascript" src="calculate.js"></script>

But I don't know how to display the result of what that function returns.

I manage to do it as a hyperlink and is working but I want just to display to a page without the user click on it.

<td height="39" colspan="4" class="table2"><a href="javascript:calculate(<? echo $dropoffperiod; ?>,2,0,1)"> see price</a></td>


Can you please help me how I can do that?

Thank you,
Xenia

Last edited by xenia : 05-04-2006 at 09:08 AM.
xenia is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-04-2006, 09:55 AM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Code:
<td height="39" colspan="4" class="table2">
  <script type="text/javascript">
    document.write(calculate(<? echo $dropoffperiod; ?>,2,0,1));
  </script>
</td>
A better option might be to translate the calculate() function to PHP and have it execute on the server along with the rest of it.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-04-2006, 10:32 AM Re: Where to put javascript function
Super Talker

Posts: 145
I put the code that you post and is working.
What you think is better to conver to a php request or use is as you showed me?

Thank you,
Xenia
xenia is offline
Reply With Quote
View Public Profile
 
Old 05-04-2006, 12:09 PM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
I'd say it would be better to have the calculate() function as PHP (depending on what it does/what other resources it needs) cos then it's all together, easier to manage, and takes the processing away from the client side which can't be relied upon (What if the user doesn't have JavaScript enabled?)
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-05-2006, 04:34 AM Re: Where to put javascript function
Super Talker

Posts: 145
Do you think that it is better to create the function in PHP rather than in javascript?
xenia is offline
Reply With Quote
View Public Profile
 
Old 05-05-2006, 04:44 AM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Yes.

-
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-05-2006, 06:38 AM Re: Where to put javascript function
Super Talker

Posts: 145
Thank you
xenia is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Where to put javascript function
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15639 seconds with 12 queries