What are the differences between using "javascript:location.href=blablub" and "javascript:document.formularname.submit()" for passing variables in PHP?

When passing variables in PHP, using "javascript:location.href=blablub" will redirect the user to a new URL with the specified value, while "javascript:document.formularname.submit()" will submit a form with the specified value. The former is useful for simple redirections, while the latter is more suitable for submitting form data.

<?php
// Using "javascript:location.href=blablub" for passing variables
$variable = "example";
echo "<a href='javascript:location.href=\"newpage.php?var=$variable\"'>Click here</a>";

// Using "javascript:document.formularname.submit()" for passing variables
echo "<form name='myForm' method='post' action='submit.php'>";
echo "<input type='hidden' name='var' value='$variable'>";
echo "<a href='javascript:document.myForm.submit()'>Submit Form</a>";
echo "</form>";
?>