Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:58:44+00:00 2026-06-09T17:58:44+00:00

I am using Ajax to populate a drop down menu from the database, my

  • 0

I am using Ajax to populate a drop down menu from the database, my question is how do I onclick redirect it to a page along with the CARD_ID i got back from the database?

right now when I click on it it’s displaying the card name in the search bar which is part of what I want but now I need the other half the redirection. How can I achieve this?

<?php
    $mysqli = mysqli_connect('localhost', 'root', '', 'draftdb');

if(mysqli_connect_errno()) 
{
    echo "Connection Failed: " . mysqli_connect_errno();
    exit();
}

    $str = $_GET['content'];
    if(strlen($str))
    {
        $sel = mysqli_query($mysqli, "select CARD_NAME, CARD_ID,CARD_TYPE from cards where CARD_NAME like '".trim($str)."%'");
        if(mysqli_num_rows($sel))
        {
            echo "<table border =\"0\" width=\"100%\">\n";
            if(mysqli_num_rows($sel))
            {
                echo "<script language=\"javascript\">box('1');</script>";
                while($row = mysqli_fetch_array($sel))
                {
                    $card_info = str_ireplace($str,"<b>".$str."</b>",($row['CARD_NAME']));
                    $card_type = str_ireplace($str,"<b>".$str."</b>",($row['CARD_TYPE']));

                    echo "<tr id=\"word".$row['CARD_ID']."\" onmouseover=\"highlight(1,'".$row['CARD_ID']."');\" onmouseout=\"highlight(0,'".$row['CARD_ID']."');\" onClick=\"display('".$row['CARD_NAME']."');\" >\n<td>".$card_info." ".$card_type."</td>\n</tr>\n";


                }
            }
            echo "</table>";
        }
    }
    else
    {
        echo "<script language=\"javascript\">box('0');</script>";
    }
?>  

the javascript.

subject_id = '';
function handleHttpResponse() {
    if (http.readyState == 4) {
        if (subject_id != '') {
            document.getElementById(subject_id).innerHTML = http.responseText;
        }
    }
}
function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object

function getScriptPage(div_id,content_id)
{
    subject_id = div_id;
    content = document.getElementById(content_id).value;
    http.open("GET", "script_page.php?content=" + escape(content), true);
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
    if(content.length>0)
        box('1');
    else
        box('0');

}   

function highlight(action,id)
{
  if(action)    
    document.getElementById('word'+id).bgColor = "#C2B8F5";
  else
    document.getElementById('word'+id).bgColor = "#F8F8F8";
}
function display(word)
{
    document.getElementById('text_content').value = word;
    document.getElementById('box').style.display = 'none';
    document.getElementById('text_content').focus();
}
function box(act)
{
  if(act=='0')  
  {
    document.getElementById('box').style.display = 'none';

  }
  else
    document.getElementById('box').style.display = 'block';
}

the html

<div class="ajax-div">

    <div class="searchbar">

     <input type="text" onKeyUp="getScriptPage('box','text_content')" id="text_content">

    </div>

    <div id="box"></div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:58:45+00:00Added an answer on June 9, 2026 at 5:58 pm

    I’m not sure what you are trying to do, but it seems you want something like this:

    1- Change the way you display your rows so that the ID gets sent to your function as well:

    echo "<tr id=\"word".$row['CARD_ID']."\" onmouseover=\"highlight(1,'".$row['CARD_ID']."');\" onmouseout=\"highlight(0,'".$row['CARD_ID']."');\" 
       onClick=\"display('".$row['CARD_NAME']."', " . $row['CARD_ID'] . ");\" >\n<td>".$card_info." ".$card_type."</td>\n</tr>\n";
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^
    

    2- Change your display function to redirect

    function display(word, id)
    {
        // document.getElementById('text_content').value = word;
        // document.getElementById('box').style.display = 'none';
        // document.getElementById('text_content').focus();
        window.location.href = "some_page.php?card_id=" + id;
    }
    

    I have commented out the original lines because there doesn’t seem much point in doing stuff on a page you are leaving anyway. You could also completely remove the word parameter if this is the solution you are looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to populate a DropDown control on page load using AJAX. I have
I have 3 drop down selectors using AJAX (first is populated, after selection the
I have this triple dropdown which works great from http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html Is it possible to
I'm using ajax requests to populate modal popup windows with data that users have
I'm using AJAX to get data for several business-card like divs on my page
I am using ajax calendar extender for 'From date' and 'To date' text box,
Basically, I have populated a dropdown list using php from a database on a
My site has a form which insert records in a database using ajax, at
I'm using a repeater on my page. I want to populate this repeater based
I have multiple drop down lists on a page. They all contain list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.