0

I have the following code

<form name="form" id="form">
  <select name="name"  onChange=" <?php $do=&something('val')?>">
    <option value="val1">val2</option>
    <option>val1</option>
  </select>
</form>

Im trying to use the options value as a parameter for a function that passes by referance how do i do this correctly

  • You close two selects, but only open one, have your select options don't have any values assigned - or names of that matter. And the options without name (might be a typo) don't have the correct closing for the option. – Jon Apr 15 '13 at 21:42
  • It seems that you are mixing Javascript and PHP. PHP is executed on the server side. After the execution, the content is sent to the client (pure HTML with optionnal JS and CSS). And then, Javascript is executed on the client side. If you want to use data sent by your form, refer to `$_POST` or `$_GET` – MatRt Apr 15 '13 at 21:42

2 Answers2

1

You cannot use PHP code in the onChange event of a select html element. You should use Javascript in the onChange event.

Jan-Henk
  • 4,864
  • 1
  • 24
  • 38
0

Beside the fact you have a wrong HTML and wrong javascript, the question is still how to use the values as variable to a function? So...

<select name="name">
<option value="value2">value2</option>
<option value="value3">value3</option
</select>

with value3 selected

after posting this, you will have created variable like this

$_POST['name'] = 'value3'

then

$param1 = $_POST['name'];

will recieve the value 'value3'.

So you can pass it to a function:

function myFunc($param1) {
....
}
myFunc($param1);
Royal Bg
  • 6,988
  • 1
  • 18
  • 24