jPoint and jQuery marriage... sometime bliss and sometimes pain

Nov 5, 2009 at 3:05 AM
Edited Nov 5, 2009 at 3:06 AM

Hi jPointers,

I have a floating div that has a text space on the a newform.aspx. I want to setup both a mouseover and change event for the form fields. The mouseover event would cause the code to change the text in the div to reflect input instructions for that field. The change event would allow me to cascade selection options as well as hide/unhide pertinent fields. Here is what I am having trouble with. I am able to use jQuery to set the events, but they don't fire the way I think they should. This clearly demonstrates my lack of understanding :-) I have been using $(jP.Form.{fieldname}.ItemRow).find("input").change()... This fires on startup but not when the field actually changes. I have tried it without the find and against the Item without success. Suggestions on how to accomplish this?

Coordinator
Nov 5, 2009 at 3:56 AM
Edited Nov 5, 2009 at 3:59 AM

Try this $(jP.Form.{fieldname}.Item).find("input").change(function(){<your code>});

Item gives you the html element of the <span> that contains the <input> field.

ItemRow gives you the html element of the <tr> of the entire row.

Also, if your input field is not a <input>, but a <select> you should use this instead to find either

$(jP.Form.{fieldname}.Item).find("input,select").change(function(){<your code>});

Coordinator
Nov 5, 2009 at 5:36 AM

Ken you have beet me to the punch.

Bill you were really close you just had to finish the content of the "change" function.

Jquery change: http://docs.jquery.com/Events/change

Also check new 'cross site lookup' example on sharejpoint.com that might be of interest to you.

Nov 5, 2009 at 5:38 AM

Ken, my mouseovers are working great, but the change event is not firing. Since I am using the converttodropdown.js script, is it possible that the jQuery is evaluated before the convert script is run? I don't know the mechanics of jQuery and how it attaches the events. Is it possible that the convert script somehow steps on the JQuery? I have tried inverting the order of the convert vs. the jquery events with no success. Ideas? Maybe I have to do a little mod the the convertodropdown script to get this to work correctly? Thanks for the help.

Bill

Coordinator
Nov 5, 2009 at 6:43 AM

Bill, after using converttodropdown the dropdown <select> field has the id of {fieldname}_ddl.  You can attach the change event to that field like for example if your field name is fieldname, then

$("#fieldname_ddl").change(function(){

    alert("value changed to " + $("#fieldname_ddl").val());

});

The other event you can use is blur which fires as your focus leaves the field.

$("#fieldname_ddl").blur(function(){

    alert("value changed to " + $("#fieldname_ddl").val());

});

Nov 5, 2009 at 4:44 PM

Ken, I have started trying to utilize your new cross site lookup to build the lists. I will start a new discussion on that...