Changing public variable from a function (JS)

How can I change a public/inspector variable from a function? I left out where I call the function for simplicity sake. This code here is throwing an error:

// The Variable I am trying to change
var target : Transform;

function NavP1 ()
{
    target = GameObject.FindWithTag  ("NavP1").transform;
}

I have tried creating the variable inside the function and that seems to not work either. Thanks!

Ugh I got it to work. The problem was actually in the code I didn’t upload, go figure.