Jump to content

Using Form to search Database


fisher7679

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
https://forums.phpfreaks.com/topic/282576-using-form-to-search-database/
Share on other sites

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() },

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.