0

Hi

I have a select list on my form as the following

<form name="source_form">
                    <select id="sel_source_zero" name="sel_source_zero">
                    <?php
                    $sources = _ajax_get_news_sources();
                    foreach ($sources as $key => $value) {
                        print ("<option value=\"$key\">$value</option>\n");
                    }
                    ?>
                    </select>
                    <input type="submit" value="Submit" />
                </form>

When the user selects a value from the list, I want to take that value and pass it into a PHP function and return a list of IDs. Once I have the source value and the IDs, I want to update my URL with those values. My entire code is as follows

<?php
                       $source_var = $_GET['sel_source_zero'];
                       $action_zero = "/news/date/"._ajax_condition_ids_final_unique_plus_seperated($source_var)."/$source_var";
                ?>
                
                <script type="text/javascript">
                $("#sel_source_zero").change(function (){
                $.ajax()
                });
                </script>

                <form name="source_form" method="get">
                    <select id="sel_source_zero" name="sel_source_zero">
                    <?php
                    $sources = _ajax_get_news_sources();
                    foreach ($sources as $key => $value) {
                        print ("<option value=\"$key\">$value</option>\n");
                    }
                    ?>
                    </select>
                    <input type="submit" value="Submit" />
                </form>

I have approached this problem by first trying to store the selected value ($("sel_source_zero").value()) into a PHP variable using AJAX. This is where I got stuck. I am trying to use $.ajax() function from jQuery appended to Drupal, but I'm not sure how to approach this. If I can some how store the JavaScript variable into PHP variable then I will be able to use my new converted to PHP source variable and pass that into my function to get the list of IDs and then update my URL. But I'm not even sure if this is the right approach. If anyone can point me in the right direction to how I can update my URL with the selected value and returned PHP values returned from a function that uses the selected value as it's parameter, I would greatly appreciate it.

Edited by gambit_1607: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Airshow
0

All very confused Gambit.

Let's try for some decomposition:

GAMBIT: I have approached this problem by first trying to store the selected value ($("sel_source_zero").value()) into a PHP variable using AJAX. I am trying to use $.ajax() function from jQuery appended to Drupal, but I'm not sure how to approach this.
INTERPRETATION: I wish to pass $("sel_source_zero").value() to a php script using AJAX.

GAMBIT: If I can some how store the JavaScript variable into PHP variable then I will be able to use my new converted to PHP source variable and pass that into my function to get the list of IDs and ...
INTERPRETATION: The php script will return a list of IDs.

GAMBIT: ... then update my URL.
INTERPRETATION: Very difficult. The statement is too imprecise. What URL, where does it appear in the code? If you mean the current window.location then why use AJAX? What exactly should happen to the returned list of ids? What, if anything, should be displayed to the user at this point?

Airshow

-1

ok. all i'm trying to ask is how to convert a javascript variable into a php variable. i thought you'd be intuitive enough to understand that. why are you interpreting when u understand what i'm saying. i did more researching and the answer lies in json. if you knwo more about that reply or don't bother

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.