This wont work as JavaScript is executed in the browser and PHP executed on the server .. so the PHP would be executed before the page is loaded in the browser and the JavaScript executed ....
What you could do is POST
the variables to PHP :
var dirnm = jQuery.trim($('#dirname').val());
var parent1 = jQuery.trim($('#parent').val());
$.post("sript.php", { dirname: dirnm, parent: parent1 } );
then in PHP (script.php
) :
// get the variables from $_POST
$dir = $_POST['dirname'];
$par = $_POST['parent'];
$this->url(array('controller'=>'index','action'=>'dirnameex','dirname'=> $dir,'parent'=> $par))
Docs here for $.post() (jQuery) and Docs here for $_POST (PHP)