This topic is locked
[SOLVED]

 js getvalue of file/image on load

4/17/2012 2:11:15 PM
PHPRunner General questions
W
wildwally author

Having trouble with the getvalue on load for the Javascript. I want the fields to display if they have attachments loaded to them using this code:



if(ctrlattach2.getValue()!='')

{

attach2.style.display = '';

}else{

attach2.style.display = '';

}

if(ctrlattach3.getValue()!='')

{

attach3.style.display = '';

}else{

attach3.style.display = '';

}


Is there something different that needs to be done? Using the same variables in a change event works - using this code:


ctrlattach1.on('change', function(e){

if (this.getValue() != '')

{

attach2.style.display = '';

}else{

attach2.style.display = 'none';

}

});

ctrlattach2.on('change', function(e){

if (this.getValue() != '')

{

attach3.style.display = '';

}else{

attach3.style.display = 'none';

}

});


when the page loads the two rows are not showing up; however, when i make a change to the first item and the second they appear. So wondering if the getvalue should look at something different for File/image fields.

C
cgphp 4/18/2012

The else branch has the same of the if branch. Please, try the following version:

if(ctrlattach2.getValue()!='')

{

attach2.style.display = '';

}else{

attach2.style.display = 'none';

}

if(ctrlattach3.getValue()!='')

{

attach3.style.display = '';

}else{

attach3.style.display = 'none';

}
W
wildwally author 4/18/2012



The else branch has the same of the if branch. Please, try the following version:

if(ctrlattach2.getValue()!='')

{

attach2.style.display = '';

}else{

attach2.style.display = 'none';

}

if(ctrlattach3.getValue()!='')

{

attach3.style.display = '';

}else{

attach3.style.display = 'none';

}



Wow, didn't even catch that in this post; however, I had fixed what you pointed out along the lines and still no luck. It appears that the getValue is looking at the first box in the file/image field. Is there something I need to do to get the getvalue to look at the second box "field" to the right of Filename? The reason I say this is when I click browse and add a new record there is now a value in the first field and then the code detects. I should make note that this is on the edit page.

C
cgphp 4/19/2012

Check with firebug the id of the second field and and enter the following code:

if($("#id_of_the_second_field").val() != '')

{

attach2.style.display = '';

}else{

attach2.style.display = 'none';

}
W
wildwally author 4/19/2012



Check with firebug the id of the second field and and enter the following code:

if($("#id_of_the_second_field").val() != '')

{

attach2.style.display = '';

}else{

attach2.style.display = 'none';

}



Got it, thanks.

C
cgphp 4/19/2012
W
wildwally author 4/19/2012



Check this video: http://www.youtube.c...h?v=-pT_pDe54aA


Got it thanks for the help.