Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 145
Trades: 0
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 10:08 AM..
xenia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-04-2006, 10:55 AM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
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!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-04-2006, 11:32 AM Re: Where to put javascript function
Super Talker

Posts: 145
Trades: 0
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, 01:09 PM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
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!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-05-2006, 05:34 AM Re: Where to put javascript function
Super Talker

Posts: 145
Trades: 0
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, 05:44 AM Re: Where to put javascript function
Minaki's Avatar
Defies a Status

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

-
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 05-05-2006, 07:38 AM Re: Where to put javascript function
Super Talker

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.24948 seconds with 12 queries