Problem in assigning a javascript variable value to a PHP variable

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 3434 Views - Last Post: 29 November 2012 - 09:07 AM Rate Topic: -----

#16 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3079
  • View blog
  • Posts: 10,798
  • Joined: 08-August 08

Re: Problem in assigning a javascript variable value to a PHP variable

Posted 29 November 2012 - 06:04 AM

This looks like a poor man's version of Ajax. I recommend you read up on it and JQuery.
Was This Post Helpful? 1
  • +
  • -

#17 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Problem in assigning a javascript variable value to a PHP variable

Posted 29 November 2012 - 08:38 AM

Aye, so you did what you were after, but you REALLY don't want to do that in practice.
I mean, what does it differ in outputting value from PHP variable to a hidden div tag and then getting it's contents trough JS/DOM?

You should definitely read up on AJAX and use jQuery to ease the pain. ;)

Also:

Quote

This is the first time I am programming in PHP.
I didn't see that originally. If you're a beginner to both PHP and Javascript, than you want to get trough some comprehensive material to get to know them in more structural way. Lot's of problems were already solved times and again, as you know, and it's easier to get to know them in front, rather than when it's too late. ;)
Was This Post Helpful? 1
  • +
  • -

#18 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,907
  • Joined: 30-April 10

Re: Problem in assigning a javascript variable value to a PHP variable

Posted 29 November 2012 - 09:07 AM

View PostCTphpnwb, on 29 November 2012 - 06:04 AM, said:

This looks like a poor man's version of Ajax. I recommend you read up on it and Jquery.

Poor mans Ajax...HAHAHA love it.

I agree with CTphpnwb, Learning ajax and jquery now if you expect to be working with Javascript and PHP together would be better than just learning PHP and trying to echo into Javascript.

Separation of code is a great thing and that is something you should also pickup as a beginner.
IE:
HTML
PHP
Javascript
CSS

These are all separately functioning languages, they should be all separate from each other.

** NOTE FOR THE BEGINNER **
As a side note for a beginner I think that when you get to using MySQL (or what ever database) You need to ignore the tutorials that show using mysql_ functions for it is depreciated. Look into PDO and MySQLi for database work.

php.net said:

mysql_connect() -
Suggested alternatives - Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

mysqli_connect()
PDO::__construct()

Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2