Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


writing a PHP command as a string

writing a PHP command as a string

writing a PHP command as a string

I want to call a PHP function based on information extracted from a form with javascript

hard-coded works fine:

if (x=="BSP"){
if (b){
var thecontent="<?php distincttype('BSP') ?>";
document.getElementById("BSP").innerHTML =thecontent;
document.getElementById("BSP").innerHTML ="";

What I am looking to do is change the php element depending on the content of a form element to replace the 'BSP' with the variable y
var y=document.forms["FindForm"]["myRef"].value; (assume value is "XYZ")

by creating a string variable thecontent
var thecontent="<?php distincttype('"+y+"') >?";

I can create the variable but it just doesnt work when the routine is substituted for the hard code.

Javascript remains a mystery to me so any help welcome and plkease be gentle with me :)

RE: writing a PHP command as a string

PHP runs BEFORE the javascript is even delivered to the browser, so you will have to use AJAX to call the PHP function.


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: writing a PHP command as a string

You can't. PHP and Javascript cannot directly interact. PHP is executed on the server. By the time JS runs, whatever PHP you have has already run, and delivered whatever it produced to the browser.

If you need to execute a PHP function based on a JS value, you'll need to look into Ajax.

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close