Reputation: 808
I'm trying to use this Javascript
snippet below to display a DIV
in a view Dynamically. But it gives me this error new:624 Uncaught SyntaxError: missing ) after argument list
for this line in the snippet $("#order_country"]).change(function() {
window.onload = function() {
$("#order_country"]).change(function() {
var val = $(this).val();
$("#country_div").toggle(val == "us");
});
});
I really can't find the missing )
, could anyone take a look at this and see if they can find it.
Upvotes: 0
Views: 106
Reputation: 2293
In order to make the line appear and disappear dynamically, you'll need to use javascript:
$(function() {
$("#id-you-give-to-country_select"]).change(function() {
var val = $(this).val();
$("#id-you-give-to-div").toggle(val == "us");
});
});
One gotcha is that in your if you're comparing :country
(symbol) with "US" (string), which will never succeed.
Just for testing, you can also add alert(val);
right after the call to toggle
, so you can see that the code is running and what the values are.
EDIT - THIS VERSION WORKS
First, the country-select
has an ID
generated in the html
, it is #order_country
Then I had to make few adjustments to the code, below is the working version
window.onload = function() {
$("#order_country").change(function() {
var val = $(this).val();
$("#country_div").toggle(val == "US");
});
};
Upvotes: 1