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

  • Home
  • SEARCH
  • 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 8189983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:27:59+00:00 2026-06-07T03:27:59+00:00

I have posted a few questions previously on how to do the same thing,

  • 0

I have posted a few questions previously on how to do the same thing, and people have pointed me in the right direction. So my apologies if this is getting repetitive. However I am posting this time to see if someone could spare a couple of seconds to help me with javascript.

I have a form that already submits data into a different table, and want to implement a “pre-canned response feature”. This would simply be a drop list selection that when the onChange event fires of an option list it runs the javascript that populates a following text area with appropriate data.

I believe as it is already in a form, I can’t simply put it in another form and use submit, also, I want to be able to do this without refreshing the page.`

<form action="<?=base_url();?>ticket/addmessage/<?=$ticket_details['id'];?>/" enctype="multipart/form-data" method="post" name="message">

        <label for="frm_precan">Canned Response</label>
        <span class="input">                        
            <select id="frm_precan" name="precan" onchange="updateText()">
                <option value="">--Please Select--</option>
                <?php foreach($precan_list as $precan) :?>
                    <option value="<?=$precan['id']; ?>"><?=$precan['name'];?></option>
                <?php endforeach; ?>            
            </select>
        </span>

        <ul>
            <li><label for="message">Message<span class="req">*</span></label><span class="input"></span><br/></li> 
        </ul>   
        <textarea style="width: 100%; margin: 0; padding: 0; border-width: 1; font-family: courier;" name="message" rows="10" id="text_area"></textarea>
        <button type="submit"><span>Add Message</span></button>

</form>

This is my HTML form. It uses PHP via SQL to populate the option list, as the pre-canned messages are stored in SQL table.

So what I need to do is somehow link this Javascript (that is called on the onChange):

        function updateText()
       {
       var message = document.getElementById('frm_precan').value;
       $('#text_area').val(message)
       };

(very basic, I know, but this is where I struggle) So this code wants to pass the ('frm_precan').value; (which is the ID in the table, and the field by which I want to query the correct message)… to a php file that looks like this:

    public function get_message($message_id)
    {
        $sql_list  =
        "
        SELECT *
        FROM  ".$this->tables_automessages."
        WHERE id = '".mysql_real_escape_string($message_id)."'";

        $query = $this->db->query($sql_list);
        if($query->num_rows() > 0)
            {
            foreach ($query->result_array() as $row)
                {
                $return[] =
                array(
                        'message'                   =>  $row['message']

                    );
                }
            return $return;
            }
        else return false;
        }
}

O, and I am using code ignitor, so this could also be a reason why I am getting confused. So the variable wants to come out of the javascript into a controller then go to the SQL query.

If someone can understand what I mean, I will be amazed… and very grateful.

  • 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-07T03:28:01+00:00Added an answer on June 7, 2026 at 3:28 am

    To use post in your ajax call:

    function updateText()
    {
        $.ajax({
            url: '/controller/get_message',
            data: {message_id:$('#frm_precan').val()},//no need to json encode, jQ does this for you
            type: 'POST',
            dataType: 'json',//or omit, jQ does an intelligent guess
            success: function(response)
            {
                console.log(responese);
                //function will be called when the ajax call is completed
            }
        });
    }
    

    In your controller, the get_message member function could look like this:

    public function get_message()
    {
        $id = $this->input->post('message_id');//=== data key used to send request
        //do your query 
    }
    

    Here is a similar question BTW
    And here, you can find all sorts of things you can specify with the jQuery.ajax method ($.ajax is the same thing, $ and jQuery are synonyms)

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

Sidebar

Related Questions

Firstly, Modifying may be the wrong term, I see a few people have posted
sorry for my English. I previously posted this question as: Multiple ViewModels request same
I've posted a few questions prior to this one regarding the use of std::function
I have posted a question on here previously asking similar advise, but this project
I'm brand new to Apache Ivy and have posted a few other Ivy-related questions
I have recently posted a few questions to understand recursion and backtrack, I felt
[I have posted this at the Django users | Google Groups also.] Using the
So I just have posted a question about this code (which was answered): $(document).ready(Main);
This sounds like a problem many others have posted about, but there's a nuance
I have posted this question on the Ext-GWT forums, I am just hoping that

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.