Hi Sagiw and welcome to our forum!
InfoPath comes with 25 out-of-box samples that include lots of JS. To access the script.js files for them, start InfoPath and choose Sample Forms (under Form Categories). Select one of the forms and click Design This Form in the left taskpane. For example, Service Request. Now, click File->Extract Form Files and create a new folder somewhere where you can extract the files. Navigate to that folder in Windows Explorer. Right click on script.js file and choose open with Notepad. Search for Common Form Template Functions and copy everything from that comment down into the script.js file that you are using for your form. Now, you can use SetNodeValue like this:
setNodeValue(XDocument.DOM.selectSingleNode("/my:myFields/my:field1"),'text');
Have fun!
Patrick Halstead
Project Manager at Qdabra