0

I am struggling to get the Javascript action going in the "onchange" event in the below example. I have tried all sorts of different syntax, but it does not work.

function display(){

    $headingData ='<select name="input" id="input" onchange="$("#frmInput").submit()" >';
        $headingData.='<option value="...." '.$selected.'>Selection1</option>';
        $headingData.='<option value="...." '.$selected.'>Selection2</option>';
    $headingData.='</select>

    return $headingData;
}
6
  • Attach the handler properly in Javascript instead of trying to use inline attributes, which is as bad as eval and difficult to manage given the required escaping. Commented Sep 16, 2018 at 4:09
  • ok, can you give me an example? Commented Sep 16, 2018 at 4:10
  • 1
    onchange="$("#frmInput").submit()" uses two levels of double quotes... Trying using &quot; as an entity within the double quotes, or a backslashed single quotes. Commented Sep 16, 2018 at 4:12
  • 1
    You need to change onchange="$("#frmInput").submit()" to onchange="$(\'#frmInput\').submit()" Commented Sep 16, 2018 at 4:15
  • yes, that did the trick, please create answer so that I can tick it off, thanks Commented Sep 16, 2018 at 4:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.