On PHP and HTML Forms...

CrackaLackaZe

Senior member
Jun 29, 2002
922
0
76
I am writing a drop down menu in php, and I want to pass the updated selected option as a variable into another function in blah.php. But I haven't found a way to get it to work yet. Does anyone see anything wrong?

 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
without a bigger sample of whats really going on heres the only things i might change:
(mine wasn't playing nice in the echo statement...also you shouldn't have to go back to your home directory to direct it to blah.php (if its in the same directory)
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
What's this function in blah.php called? It's not returnTest() is it?

The first thing that I see wrong is the syntax for your onchange event. I assume you're trying to use the value of the php variable $testFile to pass to a javascript function called returnTest(). You'll probably want to quote the value in javascript and add an echo to the php part because all you're doing is making a statement that doesn't do anything by stating a variable name. Or is <?php= $testFile ?> valid syntax?
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
Originally posted by: kamper
What's this function in blah.php called? It's not returnTest() is it?

The first thing that I see wrong is the syntax for your onchange event. I assume you're trying to use the value of the php variable $testFile to pass to a javascript function called returnTest(). You'll probably want to quote the value in javascript and add an echo to the php part because all you're doing is making a statement that doesn't do anything by stating a variable name. Or is <?php= $testFile ?> valid syntax?

in that section, he would need to <?php echo $testFile; ?> :)
 

CrackaLackaZe

Senior member
Jun 29, 2002
922
0
76
Originally posted by: kamper
What's this function in blah.php called? It's not returnTest() is it?

The first thing that I see wrong is the syntax for your onchange event. I assume you're trying to use the value of the php variable $testFile to pass to a javascript function called returnTest(). You'll probably want to quote the value in javascript and add an echo to the php part because all you're doing is making a statement that doesn't do anything by stating a variable name. Or is <?php= $testFile ?> valid syntax?

Yeah, returnTest() is a php function in blah.php. Would that be wrong? I wasn't sure if I could pass the variable straight into a php function. Would I have to pass it into a javascript function first?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
The way you have it, assuming you correct the syntax error, the browser will look for a javascript function called returnTest. What you need to do is submit the form, grab the value that was changed, pass that to the php function and then send the page back to the browser.

I think, though, that you don't fully understand where and why each language executes. Not trying to be offensive, just helpful I hope :). I would reccomend sticking to just one language at a time for now until you get a little more familiar with each. Write some html pages with javascript that does fancy stuff on the client-side, write some php pages with no javascript that does some fancy stuff on the server-side and then put the two together. It shouldn't take too long.