php variable retrieval

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I need some help regarding variable passing in php. I have a script which
writes the current form text box values to an email script which works
correctly. Should I use a variable which was created on the page within a
javascript to leaves me with a blank value.

As an example,

$sf_Bizname = $HTTP_POST_VARS['BizName']  works when BizName is the "name"
of the textbox. It doesn't when it is declared as var BizName = "MyBiz".


Re: php variable retrieval

Quoted text here. Click to load it

Maybe you should post a complete, small, to the point example!

Re: php variable retrieval

Thanks All,

I think during my frustration I didn't change the GET back to a POST while
trying to use a type="hidden". It now works correctly.
"Erwin Moller"
Quoted text here. Click to load it
Quoted text here. Click to load it

Re: php variable retrieval

Quoted text here. Click to load it

PHP is a server-side language, so it knows nothing of any JavaScript
that's taking place on the client-side unless you force it to. The best
you can do is to set the contents of a form input field via JavaScript,
like so:

<script language="Javascript">
function SetBiz(item){
  var BizName = "MyBiz";
  item.value = BizName;
<form method="post" action="test.php">
<input type="text" name="biznamefield" onClick="javascript:MyBiz(this);">
<input type="submit"></form>

Upon submitting this form, if the user had clicked inside the text box,
test.php would receive $_REQUEST[biznamefield]  with a value of "MyBiz."
You can use JavaScript methods other than onClick to set the field
values, of course; you could stick an onLoad() in the body tag to call a
function that would populate as many fields as you like.

While I haven't tried, I don't believe this will work on hidden fields.


Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
< | PHP scripts, webmaster resources

Site Timeline