transfering php variable to html <input...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grabber_grabbs
Forum Commoner
Posts: 60
Joined: Mon Oct 10, 2011 6:13 pm

transfering php variable to html <input...

Post by grabber_grabbs »

Hi there, i did all kind of tests here to find an answer to my problem...without success. Its a chance we all have this site to get support. thanks to you all.

Ok here is the code.
<?php
session_start();
$acctno = $_SESSION['username'];


// to transfer php variable to client side.
echo "<script language=\"javascript\" type=\"text/javascript\">
acctno = \"$acctno\";

// here a test to see if the value is transfered
alert (acctno); // the results is showing that the acctno is transfered ok.
</script>";
..
..
..// several lines of code here.
..
alert( acctno ); // here is the alert command to see if i still have a value in the variable... the results is positive.

// now here is the problem. i cannot have the results of acctno in the input field below.. (note that this field is readonly)
document.writeln('<tr><td>Compte:</td><td><input type="text" name="varacctno" value= acctno readonly></td></tr>');

the results i have is Compte : acctno

what i want is Compte : 42345

I tried with acctno between brackets, without brackets, or like this, $acctno and no positive results... i allways have the variable name into the input field.... what i want is the data inside the variable....

Sorry for my poor english.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: transfering php variable to html <input...

Post by Celauran »

Code: Select all

document.writeln('<tr><td>Compte:</td><td><input type="text" name="varacctno" value="' + acctno + '" readonly></td></tr>');
grabber_grabbs
Forum Commoner
Posts: 60
Joined: Mon Oct 10, 2011 6:13 pm

Re: transfering php variable to html <input...

Post by grabber_grabbs »

Damn, was i happy to see Celauran responding..... i knew my problem were going to be solved. Thanks again...

once again, thanks. Would like to understand why ' + acctno + '

i know somewhere else in my project, i have this and this is working
Echo " <input type=hidden name=\"ID_NUM\" value=\"$prodno\"> ";
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: transfering php variable to html <input...

Post by Celauran »

One is PHP, one is JavaScript. Different languages, different syntax. The concatenation operator in PHP is . whereas JavaScript uses +
Post Reply