Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-10-14
12
Medium Priority
?
75 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
  • 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 60

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 60

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 60

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 60

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 60

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

877 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