Jump to content

Using Form to search Database


fisher7679
Go to solution Solved by Ch0cu3r,

Recommended Posts

To be honest I am sure this is something simple that I am missing or just not understanding. What I am trying to do is use a dropdown menu to make a selection to search a db and display the results. The php portion works fine as I have hard coded the search criteria into it and it displays the results just fine. I can also use a plain text box and type the search string in with it displaying the results as well. Just not sure what I am doing wrong on the dropdown menu form/ Here is the for code I am using.

<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    function get() {
        $('#data').hide();
        $.post('data.php', { name: form.name.value },
        function (output) {
            $('#data').html(output).fadeIn(1000);
        });
    }
</script>
</head>
<body bgcolor="#2E64FE">
<p></p>
<p></p>
<form action=""><select name="genetics"> <option value="Item1">Item1</option> <option value="Item2">Item2</option> <option value="Item3">Item3</option> <option value="Item4">Item4</option> </select><input type="hidden" name="option value" /> <input type="button" value="Search" onclick="get();" />
<div id="data"></div>
</form>
</body>
</html

Any help or direction would be great, Thanks in advance!

Link to comment
Share on other sites

  • Solution

The line here

$.post('data.php', { name: form.name.value },

Specifically the form.name.value part is looking for a form with the id of form and a field within that form named as name.

 

This is how you'll get the selected value from the select menu using JQuery.

$.post('data.php', { name: $('select[name=genetics]').val() },
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.