Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Auto fill form element AND submit onClick (jQuery)
Old 12-18-2009, 12:08 PM Auto fill form element AND submit onClick (jQuery)
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Hello,

I have a search form with an autocomplete function. At the moment, it will fill the form with the value in the autocomplete, but you have to hit search after it is filled. How would I go about filling the form input and submitting the form onClick? Code is below...

The jQuery
Code:
function suggest(inputString){
        if(inputString.length == 0) {
            $('#suggestions').fadeOut();
        } else {
        $('#search').addClass('load');
            $.post("autosuggest.php", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').fadeIn();
                    $('#suggestionsList').html(data);
                    $('#search').removeClass('load');
                }
            });
        }
    }

    function fill(thisValue) {
        $('#search').val(thisValue);
        setTimeout("$('#suggestions').fadeOut();", 300);
                    }
The onClick event
PHP Code:
echo '<ul id="autolist">';
while (
$result $query ->fetch_object()) {
echo 
'<li onClick="fill(\''.addslashes($result->Last_Name).'\');"><p>'.$result->Last_Name.', '.$result->First_Name.'</p></li>';
                     }
echo 
'</ul>'
werm82 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-20-2009, 10:46 AM Re: Auto fill form element AND submit onClick (jQuery)
Banned

Posts: 1
Name: asfg
Trades: 0
Welcome to AQ!
Do surf around our sub forums for more information.
linhugyup is offline
Reply With Quote
View Public Profile
 
Old 12-21-2009, 07:28 AM Re: Auto fill form element AND submit onClick (jQuery)
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Well, that wasn't much of a solution. Anyone else have some insight?
werm82 is offline
Reply With Quote
View Public Profile
 
Old 12-21-2009, 07:31 AM Re: Auto fill form element AND submit onClick (jQuery)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
document.formname.submit(); after the fill is complete
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2009, 09:45 AM Re: Auto fill form element AND submit onClick (jQuery)
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Thanks, chrishirst. But something isn't clicking.

I tried adding it inline:
HTML Code:
<li onClick="fill(\''.addslashes($result->Last_Name).'\'); document.searchForm.submit();" >
And to the external script:
Code:
    function fill(thisValue) {
        $('#search').val(thisValue);
        setTimeout("$('#suggestions').fadeOut();", 300);
        document.searchForm.submit();
                    }
Did I miss something?
werm82 is offline
Reply With Quote
View Public Profile
 
Old 12-21-2009, 10:20 AM Re: Auto fill form element AND submit onClick (jQuery)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A URL would be more of a help.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2009, 11:40 AM Re: Auto fill form element AND submit onClick (jQuery)
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Here's an example http://craigwermert.com/dummy/index.php

This is the full PHP file that the onClick event is in:
PHP Code:
<?php
   $db 
= new mysqli('localhost''craig' ,'cabana''admins');
    
    if(!
$db) {
    
        echo 
'Could not connect to the database.';
    } else {
    
        if(isset(
$_POST['queryString'])) {
            
$queryString $db->real_escape_string($_POST['queryString']);
            
            if(
strlen($queryString) >0) {

                
$query $db->query("SELECT Last_Name, First_Name, id FROM admins WHERE Last_Name LIKE '$queryString%'");
                if(
$query) {
                echo 
'<ul id="autolist">';
                    while (
$result $query ->fetch_object()) {
                         echo 
'<li onClick="fill(\''.addslashes($result->Last_Name).'\'); document.searchForm.submit();" ><p>'.$result->Last_Name.', '.$result->First_Name.'</p></li>';
                     }
                echo 
'</ul>';
                    
                } else {
                    echo 
'Houston, we had a problem...';
                }
            } else {
                
// do nothing
            
}
        } else {
            echo 
'There should be no direct access to this script!';
        }
    }
?>
werm82 is offline
Reply With Quote
View Public Profile
 
Old 12-21-2009, 03:10 PM Re: Auto fill form element AND submit onClick (jQuery)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What FF javscript error console is showing points towards tthe mix of JQuery and REAL javascript being the problem.

I don't use any of these frameworks 'cos it takes me longer to work out how to use them, than it does to write the code in the first place!

so you need to work how to write the submit function in jquery.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Auto fill form element AND submit onClick (jQuery)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28259 seconds with 12 queries