I have a text field and an input type submit. When I click on the submit button I should get a url related to the input field. But I am getting Uncaught TypeError: undefined is not a function
. Here's my code that explains more better:
<script>
$(document).ready(function(e) {
$('#search_btn').click(function() {
console.log($('#thisiswhatineed').val()); // this is working perfectly
console.log("<?php echo BASE_URL; ?>/ads/search/"); // this is also working perfectly
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" . $('#thisiswhatineed').val();
console.log(url_to_go); // this is not working and giving me the error mentioned above
});
});
</script>
In javascript, you concatenate strings with +
, not .
So:
var url_to_go =
"<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();
Use +
operator instead of .
to concatenate two strings in JavaScript.
Instead of
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" . $('#thisiswhatineed').val();
use
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();
In Javascript you use the plus symbol for concatenation.
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();