1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Function Problem

Discussion in 'JavaScript' started by selen, Jun 3, 2010.

  1. #1
    Hello, I try to modify a function, but without success not working properly because I'm very bad in javascript, so here my javascript code:

    //begin ajax grabber
    
    function validateGrabber(b_on_submit){
    
        if(document.grabber.keywords.value == '' || document.grabber.keywords.value == 'search'){
    
            alert('You did not enter a search term. Please try again.');
    
            if(b_on_submit == 'true')
    
                return false;
    
        }
    
        else{
    
            document.grabber.btn.submit();
    
        }
    
    }
    
    function grabber(inputGrabber) {
    
       if(inputGrabber.length == 0) {
    
          // Hide the suggestion box.
    
          $('#suggestions').hide();
    
       } else if(inputGrabber.length > 2) {
    
          $.post(MELODYURL2+'/ajax_grabber.php', {queryString: ""+inputGrabber+""}, function(data){
    
             if(data.length >0) {
    
                $('#suggestions').show();
    
                $('#autoSuggestionsList').html(data);
    
             }
    
          });
    
       }
    
    } // end ajax grabber
    PHP:
    and that's my template code:

    	
    <form action="{$smarty.const._URL}/search.php" method="get" id="search" name="grabber" onsubmit="return validateGrabber('true');">
    
    <input name="keywords" type="text" value="" class="search_keywords" id="inputGrabber" {if $smarty.const._SEARCHSUGGEST == 1}onkeyup="grabber(this.value);" onblur="fill();" autocomplete="off"{/if}  />  
    
    <input name="btn" value="{$lang.submit_search}" type="submit" class="search_bttn" />
    
    <div class="suggestionsBox" id="suggestions" style="display: none;">
    
    <div class="suggestionList" id="autoSuggestionsList">
    
    </div>
    </div>
    </form>
    
    	
    PHP:
    the first function doesn't show the alert and the second doesn't work at all...
     
    selen, Jun 3, 2010 IP
  2. Layoutzzz

    Layoutzzz Greenhorn

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Hi Selen
    I can see alert in my browser.

    Could you post link on live example. It will easy for debug.
     
    Layoutzzz, Jun 4, 2010 IP