0

I am having some issues getting my jquery function to take my data from my input html form element.

Here is my javascript:

<script>
$(function(){


    $('#estimate').click(function() {

        var postcode_entry = $('#postcode_entry').value;

        $("#shipping_method").html("<div style=\'margin:20px auto;width:100px;text-align:center;\'><img src=\'ext/jquery/bxGallery/spinner.gif\' /></div>").show();

        $.get("checkout_shipping.php", {country: "38", refresh_quotes: "1", postcode: postcode_entry, zone_name: "canada" }, 
                function(data){
                    $("#shipping_method").html(data);
                }
            );



    });
});

</script>

html:

<input type="text"  name="postcode" id="postcode_entry" />
<button type="button" id="estimate" >Estimate..</button>

I am not able to get the postcode_entry data into the function. if I hard code a postal code in then it works properly.

3 Answers 3

3

You seem to be accessing the value of the jQuery object using a property that is available on a DOM object.

use .val() for a jQuery object and .value for a DOM object.

$('#postcode_entry').value;

Supposed to be

$('#postcode_entry').val()  // accessing value of jQuery Object

or

$('#postcode_entry')[0].value;  // accessing value of DOM object
Sign up to request clarification or add additional context in comments.

Comments

2

Try the jQuery function val() instead of the non-existant property .value:

$('#postcode_entry').val()

Comments

2
var postcode_entry = $('#postcode_entry').val();

Comments

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.