I have this Javascript/JQuery code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
name = $("#name").val();
alert("Name: " + name);
</script>
And this HTML:
<form name="report" action="send.php" method="post">
<input type="text" name="name" id="name" value="Senna" />
<input type="submit" value="Send" />
</form>
When the page loads i get “Name: undefined” instead of “Name: Senna”.
Can someone help me to get the expected result?
You need to indicate to execute the function once the page has been loaded. Currently you are only defining it and not decalring when to execute it.
Or: