Jump to content

[SOLVED] Replace problem.


Darkness Soul

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.