Page 1 of 1

transfering php variable to html <input...

Posted: Mon Nov 07, 2011 7:59 pm
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.

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

Posted: Mon Nov 07, 2011 8:24 pm
by Celauran

Code: Select all

document.writeln('<tr><td>Compte:</td><td><input type="text" name="varacctno" value="' + acctno + '" readonly></td></tr>');

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

Posted: Mon Nov 07, 2011 8:38 pm
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\"> ";

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

Posted: Tue Nov 08, 2011 6:47 am
by Celauran
One is PHP, one is JavaScript. Different languages, different syntax. The concatenation operator in PHP is . whereas JavaScript uses +