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 Link to comment https://forums.phpfreaks.com/topic/76384-solved-replace-problem/ Share on other sites More sharing options...
fenway Posted November 7, 2007 Share Posted November 7, 2007 Which replace/ Link to comment https://forums.phpfreaks.com/topic/76384-solved-replace-problem/#findComment-386773 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. Link to comment https://forums.phpfreaks.com/topic/76384-solved-replace-problem/#findComment-386832 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? Link to comment https://forums.phpfreaks.com/topic/76384-solved-replace-problem/#findComment-386876 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 Link to comment https://forums.phpfreaks.com/topic/76384-solved-replace-problem/#findComment-386895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.