Could you point how to manipulate a textbox value before it's presented?

Hi Experts

Could you point how to manipulate a textbox value before it's presented?

Accordingly to:
img001
The value is presented with a file complete path, is it possible via jQuery to supress the path, maintaining only the file name, before it's presented ?
If so what is the event to be used?

Thanks in advance
Eduardo FuerteAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
Do you mean like this?
$(function() {
  var file = $('#textboxid').val();
  var parts = file.split('/');
  var file = parts[parts.length-1];
  $('#textboxid').val(file);
});

Open in new window

0
 
Eduardo FuerteAuthor Commented:
After some researchs;

HTML (modal view)
<div class="col-xs-20 mb40 reembolso" style="display: none;">
		<label for="reembolso" class="field-label text-muted mb10">Anexo</label>
		<div class="input-group">
			<span class="input-group-addon">
				<i class="fa fa-money c-gray"></i>
			</span>
			<span class="validar">
				<input type="text" name="anexo" class="anexo form-control gui-input br-light light" placeholder="">
			</span>
		</div>
	</div>
</div>

Open in new window


jQuery : Since it's a modal view
$('#view').on('show.bs.modal', function () {

    var str = $('#view .anexo').val();
    alert(str);  // it produces an empty value

   // Manipulate here anexo value to get the relevant part:
   
    str = str.substrring(22);
   
//Make this value to be presented:
	$('#view .anexo').val(str);
});

Open in new window


When this event is called the anexo value is still filled ?
0
 
Ray PaseurCommented:
You might also do this in the server-side script.  Have a look at the PHP basename() function and the predefined constant DIRECTORY_SEPARATOR..
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Eduardo FuerteAuthor Commented:
Since by now it's more a jQuery issue, I applied your code  on view  modal show event:

HTML in use now:
<input type="text" name="anexo" id="anexo" class="form-control gui-input br-light light" placeholder="">

Open in new window


$('#view').on('show.bs.modal', function () {
  
	var file = $("#view #anexo").val();
	var parts = file.split('/');
	var file = parts[parts.length-1];
	  
	alert(file);
	  
	$("#view #anexo").val(file);

});

Open in new window


Amazingly: The very first time the modal is called the value isn't filled:
img002

Then when it's called the next times, ok:
img003

And...the textbox doesn't assume the new value assigned:
img004
Could you give a suggestion?
0
 
Julian HansenCommented:
Probably because the first time it runs the textbox has not been populated.

What is putting the value in the text box?
0
 
Eduardo FuerteAuthor Commented:
The value is empty - accordingly the picture bellow.

It seens it has a "delay" - going the code above the logic goes right, even the first time the alert shows "0" it enables the "Download" button, if the alert shows "25" (f.e.) and the file lenght is zero it disables the "Download" button too.

$('#view').on('show.bs.modal', function () {
 
	var file = $("#view #anexo").val();
	var parts = file.split('/');
	var file = parts[parts.length-1];
	  
	alert(file.length);

	
	// Desabilita o botão de download
	 if(file.length != 0)
	 {
		$('#view #download').prop("disabled", true);     
	 }
	 else            
	 {
		$('#view #download').prop("disabled", false);
	 }
	 
// Not beeing done, yet
	$("#view #anexo").val(file);

});

Open in new window



Just the assignment is still not beeing done
0
 
Julian HansenCommented:
var file = $("#view #anexo").val();

Open in new window

Where is #anexo being set - the first line is retrieving the value of the control but something must be putting the filename in there?
0
 
Eduardo FuerteAuthor Commented:
Wouldn't be it?   (line 21 above)

	$("#view #anexo").val(file);

Open in new window

0
 
Julian HansenCommented:
Yes but you are retrieving the value on line 3 - the value that you are retrieving - something is setting that - the full path?
0
 
Eduardo FuerteAuthor Commented:
I'm just debbuging to better check and will return  here soon.
0
 
Eduardo FuerteAuthor Commented:
Thanks for help!
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.