Question: I have this code on Wordpress post:

```
<input type=text id="testni" value="la">

```

and this code in functions.php:

```
<script type="text/javascript">
          $function(){
        $("#testni").attr("value", "petra");

          }
        </script>

```

This does not work. I guess i have to add some php code?

How to call JS from php?

Answer: 
What you want is this 

```
<script type="text/javascript">
$(function(){
    $("#testni").val("petra");
});
</script>

```

[Read about DOM ready](https://stackoverflow.com/a/3259561/9618184)  

[Read about setting an input value](http://api.jquery.com/val/)
If you need to call js in wordpress.. You need to add action in functions.php file. Try the below method.

```
<?php
add_action('wp_footer','custom_script');
function custom_script(){
 echo "<script type='text/javascript'>
          $function(){
        $('#testni').attr('value', 'petra');

          }
        </script>";
}
?>

```

Or else simply add your script in header.php or footer.php.