0

I'm trying to do something pretty simple, but it just doesn't seem to be working. I have a small form that asks people for a bill amount, and then if the amount is less than 50, submitting the form will trigger an alert. When this wasn't working, I started trying to find out why. This is my current code, and there isn't a value that shows up in the console. I get a blank line, showing where it's trying to pull a value, but no value is being pulled. No errors show either.

<form id="systemForm">

<fieldset><label>Average bill amount</label><input type="text" name="billAmount" id="billAmount"/></fieldset>

<p class="test" id="test">SUBMIT</p>

<script>

$( document ).ready(function() {
    var theForm = $('#systemForm');
    var billAmountNum = $( "#billAmount" ).val();



    $( "#test" ).click(function() {
      console.log(billAmountNum);
    });
});

</script>
4
  • 1
    What is systemSize and numPanels?? Don't see either of those in your HTML Commented Jun 5, 2018 at 20:32
  • @RyanWilson Other form fields that aren't important as of yet - I deleted them out of the form when I posted it since they weren't part of the problem, but forgot to remove the variables from the script Commented Jun 5, 2018 at 20:33
  • 1
    you are setting billAmountNum = $('#billAmount').val() on the document ready, then adding an event listener to test.click, and log billAmountNum which is equal to an empty string on page load. Commented Jun 5, 2018 at 20:35
  • I do not see closing tag of form </form> Commented Jun 5, 2018 at 20:35

1 Answer 1

2

You are setting billAmountNum = $('#billAmount').val() on the document ready, then adding an event listener to test.click, and log billAmountNum which is equal to an empty string on page load.

Change this:

$( "#test" ).click(function() {
      console.log(billAmountNum);
    });

To this:

$( "#test" ).click(function() {
      console.log($( "#billAmount" ).val());
    });
Sign up to request clarification or add additional context in comments.

3 Comments

@Taplar Not at all, I sometimes just assume people will correlate my comment with the answer...thanks again. Have a good day :)
@RyanWilson Thanks... I'm a little bit rusty on this, I appreciate the help.
@mollycampbell anytime. Glad to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.