Raziel Raziel - 10 months ago 65
Javascript Question

javascript not work in xhtml page ( primefaces )

I have a text area that contains a numbers of "$VAR", i want to count the occurrence of these numbers, the javascript match function returns always null, but it works in the console ! I don't understand why ?

when i test this function match return null

var regex = new RegExp("\\$VAR", "g");
var v = $("#form\\:idtextarea").val();
var count = v.match(regex).length ;

but when i run this command under the console browser it returns the correct result !

$("#form\\:idtextarea").val().match(new RegExp("\\$VAR", "g")).length

this code is included in a XHTML page


The problem is solved when I have used the default component <h:outputScript name="file.js" /> to include javascript after an <ui:define> instead of including it directly like an html page