Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-14
12
Medium Priority
?
74 Views
Last Modified: 2016-10-26
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
0
Comment
Question by:Eduardo Fuerte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 

Author Comment

by:Eduardo Fuerte
ID: 41843657
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
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41843659
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41843670
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Eduardo Fuerte
ID: 41843765
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
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41843786
Probably because the first time it runs the textbox has not been populated.

What is putting the value in the text box?
0
 

Author Comment

by:Eduardo Fuerte
ID: 41843822
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
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41843875
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
 

Author Comment

by:Eduardo Fuerte
ID: 41843980
Wouldn't be it?   (line 21 above)

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

Open in new window

0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41844345
Yes but you are retrieving the value on line 3 - the value that you are retrieving - something is setting that - the full path?
0
 

Author Comment

by:Eduardo Fuerte
ID: 41849857
I'm just debbuging to better check and will return  here soon.
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41860098
Thanks for help!
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41860151
You are welcome.
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question