user3050136 user3050136 - 3 months ago 9
CSS Question

window location problems

Trying to do a simple search via id:

<script>
jQuery(document).ready(function($){
$(window).load(function(){
$("#submit").click(function() {
var s = $("#search").val();
var url = "/tags/" + s;

if(s == empty) {
$("#search").attr("placeholder", "הכנס תוכן לחיפוש").placeholder();
}else{
window.location.replace(url);
}
});
});
});
</script>


I want to make a windows location if the input not empty, and if the input is empty then change the place holder.

Here is the HTML:

<div class="search-box">
<input type="text" name='sec' id='search' placeholder="חפש במאמרים">
<input type="submit" value="" id='submit'>
</div>

Answer

You check for empty but it doesn't exists.. instead try:

<script>
jQuery(document).ready(function($){
    $(window).load(function(){
        $("#submit").click(function() {
            var s = $("#search").val();
            if (s != '') {
               location.replace('http://test.com/tags/' + s);
            } else {
              $("#search").attr("placeholder", "הכנס תוכן לחיפוש").placeholder();
            }
        });
    });
});
</script>