I got stuck on what seems like a trivial issue, and I'm probably going to kick myself for missing it. In any case, my problem is that I am not getting the value from the text box.
HTML:
<form>
<label for="">Enter Username:</label>
<input id="usernameText" type="text" size="30" />
<input type="button" value="Generate" onclick="generateQuery(); return false;" />
</form>
JavaScript:
<script type="text/javascript">
var username = $("#usernameText").val();
function generateQuery(){
alert(username);
}
</script>
I did the following if (jQuery) {..and made sure jQuery was loaded.
The warning displays a blank dialog box.
If I included $(document).ready();in my script, the function is generateQuerynot called. Any idea why ..?
<script type="text/javascript">
$(document).ready(function(){
var username = $("#usernameText").val();
function generateQuery(){
alert(username);
}
});
</script>
source
share