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.

Coding Forum


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



Reply
Old 12-04-2009, 08:32 AM OnClick - FWrite?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Hello, I seen to be having some trouble with mixing JavaScript and PHP.

I'm trying to make a 'Like System', sort of like Digg, and I thought it would be easy; ask the user if they like it of not, if they click no, subtract one value, if they like it, add one value. Value = 1.

Here's the code:

PHP Code:
    $reviewIDrating "rIDRatings/reviewID-$reviewID-rating.txt";
    
$myFile "$reviewIDrating";
    
$fh fopen($myFile'w') or die("can't open file");
    
$stringData "STUFF TO WRITE TO FILE";
    
fwrite($fh$stringData);
    
fclose($fh);

    echo 
"
      <select id='likemeter'>
      <option class='listdata' value='1'>Like</option>
      <option class='listheader' value='-1'>Dislike</option>
      </select>
      <script type='text/javascript'>
    function writeit() {
    document.write(document.getElementById('likemeter').value);
    }
      </script>
      <input type='button' onclick='writeit()' value='WriteIt' />
    "

The first part jsut opens the file (or creates one) according to the URL Parameter 'reviewID'. Then it writes 'STUFF TO WRITE TO FILE' in it, then closes it.

The second part, the JS, simply lets you select if you 'Like' or 'Dislike' the review. Then you click 'WriteIt', and it writes it to a blank page. All fine and dandy. That works, woohoo...

My problem is making it write what the user selected ('Like' or 'Dislike') to the file, instead of 'STUFF TO WRITE TO FILE'. I
m mixing client and server side scripting, and it's very tough.

Sorry, and thanks

-PG

Oh, and I've read all over that ActiveXObject or whatever does this sort of thing, but it only works on Windows, and you have to have weird sl2 (IDK) on you computer, so it won't work on a Mac or Linux...I happen to run Linux, my friend has a Mac, so both of us can't even test it... Please no ActiveXObject answers .
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 12-04-2009 at 08:36 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-07-2009, 06:50 AM Re: OnClick - FWrite?
Super Talker

Posts: 139
Name: John Davis
Trades: 0
Code:
$myFile = "$reviewIDrating";
This is incorrect. The result is equal to $myFile = $reviewIDrating;, but there is additional server effort to replaсe $reviewIDrating by it value.

According your question. You may to use one of two solutions:
1. Create form and submit it with selected values to php script. Such script must receive parameters and then execute stuff to write info into file.
2. Make a AJAX request to same php file like in 1 case with selected parameters.
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 12-07-2009, 03:52 PM Re: OnClick - FWrite?
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
So send the variables with a get like in php but with js and write there?
I wanted it to be like youtube, you don't leave the page.
Thanks though.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to OnClick - FWrite?
 

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