echo a form and some jquery codes

I would like to post and redirect some values to my path. I find out the best solution is using a echo form .

but my code does not work :

function goToCodes($method = '' , $tr_ids = '')
{
    $path = base_url().'cart/codes';
    $jquery = base_url().'assests/new/js/jquery.js';

    echo '<form action="'.$path.'" method="post" >';
    echo '<input name="method" type="hidden" value="'.$method.'"  />';
    echo '<input name="tr_ids" type="hidden" value="'.$tr_ids.'"  />';
    echo '<input id="goToCodeSubmit" type="submit"/>';
    echo '</form>';
    echo '<script src="'.$jquery.'"></script>';
    echo '<script>';


    echo '$(function(){
                $(#goToCodeSubmit).click();
         });';

    echo '</script>';


}

in the console I get this error :

SyntaxError: illegal character

enter image description here

Answers 1

  • You should put quotes around your jQuery selector, $("#goToCodeSubmit").

    As a side note, without the quotes around #goToCodeSumit you're attempting to reference an element by the name #goToCodeSumit, which isn't an element in the DOM. Also, the hashtag is probably the thing causing the illegal character error.


Related Articles