Muhammad Arif
Muhammad Arif

Reputation: 1022

how to remove jquery error

i want to make dynamic select boxes in php page using jquery,but when i run the code it gives me two errors SyntaxError: missing ) after argument list,firebug show this error on line

jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){

and second error is when i click on add event button it gives error ReferenceError: addRow is not defined,how i remove these 2 errors and make dynamic select box on button click,here is my code:

<script type="text/javascript">
    jQuery.noConflict();

    function addRow(btn) {
        jQuery.post("<? include(FORMKEY."/form_add_events.php"); ?>",function(data){
            $(btn).closest('table').append(data);
        });
    }
</script>

here is my form_add_events.php code:

 <?php
     $strQuery1="SELECT event_id,event_name from events";
     $result1 = $GLOBALS ['mysqli']->query ($strQuery1) or die ($GLOBALS ['mysqli']->error . __LINE__);
     echo '<tr><td><select>';
     while($ors1 = $result1->fetch_assoc()) {
         echo '<option value="'.$ors1['event_id'].'">'.$ors1['event_name'].'</option>';
     } 
     echo '</select></td></td>';
 ?>

And here is my html code:

<table>
    <tr>
        <td>
            <button type="button" value="Add" onclick="addRow(this)">Add Events</button>
        </td>
    </tr>
</table>

Upvotes: 0

Views: 95

Answers (2)

Ivo Peterka
Ivo Peterka

Reputation: 125

Don't put PHP tag into post, in place of it just call form_add_events.php, return the data you need (preferably in form like JSON, not plain HTML), add data you need to send and generate HTML in response. By the way you have syntax error in post, using quotes for string containing quoted string. You need combination of quote and apostrophe.

Upvotes: 0

lonewolf217
lonewolf217

Reputation: 629

i think your quotes are off in this line. Try using single quotes in the PHP string so they dont conflict with the double quotes of the javasacript. Also, best practice is that you use

jQuery.post("<? include(FORMKEY.'/form_add_events.php'); ?>",function(data){

Upvotes: 2

Related Questions