Solved

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

Posted on 2016-10-14
12
59 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 51

Accepted Solution

by:
Julian Hansen earned 500 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 108

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
 

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 51

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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 51

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 51

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 51

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now