1

In the editform.aspx of an item, I am trying to use jQuery to cause a pop up to go off anytime a field is changed (sort of silly, but once I get this to work, I plan on moving to doing more). However, it does not seem to work. Here is my code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<SCRIPT type=text/javascript>
    $(document).ready( function() {
        $(“select [title=’Option’]”).change( function() {
            alert("yes");
        });
    });
</SCRIPT>

I currently have this file linked in the content editor. There is a select field with title being Option in my SharePoint document, so I am not sure what the problem is. The error I receive is the following

Uncaught SyntaxError: Unexpected token ILLEGAL

Thanks for any help!

  • 4
    It's a javascript parsing error. Possibly your quotes. Try to replace ” by " and ’ by ' ? – Gert Braspenning Aug 7 '14 at 20:53
  • 2
    @GertBraspenning I agree, the code sample seems to use instad of " – Robert Lindgren Aug 8 '14 at 6:23
2

Have you tried:

$("select [title='Option']".on('change', function(){
alert("yes");
});
1

Like @cubanGuy answer..

try

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script  type=text/javascript>
    alert("yes");
</script >

If that works, then you have a typo in your code.

You could try to set "onchange" in the html code: HTML

<select title="Option" id="iCard" onchange="SetCard(this)">
<option value="0" selected="selected">Yes</option>
<option value="1">no</option>

JS

function SetCard() {
    alert("changing!!");
};

JSFIDDLE example

0

Try placing your code in "content place holder main" in editform.aspx

-1

If you are referencing to the js file, just remove those lines from the js file, use them only when embedding in HTML or ASPX page.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script  type=text/javascript>
Your function
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.