GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jan-2006, 01:01
fallen_samurai fallen_samurai is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Location: Wisconsin, USA
Posts: 29
fallen_samurai is on a distinguished road

JavaScript to PHP Data Port


Yea this is probably easier that I would assume it to be. But here is the deal anyway. I have a javascript code that returns (actively as you type) how many words are in a certain text box. When the user is done with the box and submits the form, I need to take the word count that javascript gave on the page (which is contained in a span value at the moment), and somehow route it into a hidden input field or somehow save it to a PHP value, but I can't figure out how.

<span id="review_credits">0<span>

The ID review_credits is controlled and updated by this:

PHP Code:

function CountWords(text, target, bonus_target, wc_target, base) {
    var char_count = text.value.length;
    var fullStr = text.value + " ";
    var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
    var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
    var splitString = cleanedStr.split(" ");
    var word_count = splitString.length -1;
    if (fullStr.length <2) {
        word_count = 0;
    }
    words = word_count;
    bonus = Math.floor(words / 4);
    if (bonus > 50) { bonus = 50; }
    credits = Number(base) + Number(bonus);
    document.getElementById(target).innerHTML = credits;
    document.getElementById(bonus_target).innerHTML = bonus;
    document.getElementById(wc_target).innerHTML = words;
} 



This script basically counts the words and then sends it back to the HTML page as you type in the textarea. (onKeyUp function). How can I convert that span ID (when the user is done) into a PHP variable that I can then store into a MySQL dbase?
Last edited by LuciWiz : 11-Jan-2006 at 01:04. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 13-Jan-2006, 01:04
fallen_samurai fallen_samurai is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Location: Wisconsin, USA
Posts: 29
fallen_samurai is on a distinguished road

Re: JavaScript to PHP Data Port


Nevermind once again. I just used cookies from javascript to PHP, worked quite well. I know this can be dangerous, but once I set the cookie to a variable in PHP, I removed it right after, in a split second. It would be quite hard to hack that information or retreive it from that. But all the same if they did get the info, they wouldn't know what to do with it because the numbers are hard to decipher. Oh well for them! Haha.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
An Introduction to Javascript JasonMichael Web Design Forum 2 24-Oct-2004 11:19
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13
JavaScript Tutorial Part 1 pcxgamer Web Design Forum 2 01-Dec-2003 10:16

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:15.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.