Darkness Soul Posted November 7, 2007 Share Posted November 7, 2007 Yo, I'm developing a filter using checkbox to active the options. When I check an option, its send a string to an input text and submit the form; when I uncheck, its replace for nothing and submit the form. The problem is: the first time I try to uncheck, the replace is not working. Like the exemple: > string = "" I check a, send a string; > string = "a" I uncheck a, replace fail; > string = "a" I check a, send another string; > string = "aa" I uncheck a, replace the second string; > string = "a" This "string builder" genereta a SQL script to put in a where case and when submited, filter the data. There is a prototype "trim()", its work perfectly. The function below: function filtraSelecionado ( objeto , tabela , campo , alvo , tipo ) { var ifrm_selecao = document.frm_Filtragem ; var ifrm_formulario = ifrm_selecao.formFiltro ; var ifrm_campo = ifrm_formulario[ alvo ] ; var str_condicao = "" ; var str_expressao_regular = "" ; if ( tipo == 'numero' ) { str_condicao = " "+ campo +" = "+ objeto.value +" " ; } else { str_condicao = " "+ campo +" LIKE '%"+ objeto.value +"%' " ; } while ( str_condicao.match ( ' ' ) != null ) { str_condicao = str_condicao.replace ( ' ' , ' ' ) ; } str_condicao = str_condicao.trim () ; ifrm_campo.value = ifrm_campo.value.replace ( str_condicao , '' ) ; ifrm_campo.value = ifrm_campo.value.trim () ; if ( ifrm_campo.value.length > 0 ) { str_condicao = " OR " + str_condicao ; } if ( objeto.checked != false ) { ifrm_campo.value = ifrm_campo.value + str_condicao ; } while ( ifrm_campo.value.match ( ' ' ) != null ) { ifrm_campo.value = ifrm_campo.value.replace ( ' ' , ' ' ) ; } ifrm_campo.value = ifrm_campo.value.trim () ; ifrm_campo.value = ifrm_campo.value.replace ( /OR OR/ , 'OR' ) ; ifrm_campo.value = ifrm_campo.value.replace ( /OROR/ , 'OR' ) ; ifrm_campo.value = ifrm_campo.value.replace ( /OR$/ , '' ) ; ifrm_campo.value = ifrm_campo.value.replace ( /^OR/ , '' ) ; ifrm_campo.value = ifrm_campo.value.trim () ; ifrm_formulario.submit () ; } Thanks for the help. dSoul Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2007 Share Posted November 7, 2007 Which replace/ Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted November 7, 2007 Author Share Posted November 7, 2007 Woops, I forgot that detail. the ifrm_campo.value = ifrm_campo.value.replace ( str_condicao , '' ) ; one. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2007 Share Posted November 7, 2007 And what's that regex ... and what's the string? Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted November 7, 2007 Author Share Posted November 7, 2007 when I use a string like str_condicao, the replace ignore regex.. the string is somelike " int_id = 1 " damn, after many reviews, I go check the trim function, its a prototype.. I've commented the prototype and past it as a function.. the error gone.. i will use it as function.. have no much time to accomplish this.. so, I will back to this after, for now, consider it solved.. sorry for busy :-( thanks anyway dSoul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.