0

I am having a file input field:

<input class="uploadReptCtrl" id="lang_file_1" name="photo[[1,312,3]]" type="file">

I am trying to change the third element of the array in the name attribute so that it becomes:

<input class="uploadReptCtrl" id="lang_file_1" name="photo[[1,312,4]]" type="file">

How is it possible?

1 Answer 1

1

Try this

$('#lang_file_1').attr('name','photo[[1,312,4]]')

https://jsfiddle.net/jzzL1d2r/

you can store the value in a variable and set it as

var a = 4;
$('#lang_file_1').attr('name','photo[[1,312,'+a+']]')

https://jsfiddle.net/jzzL1d2r/1/

As you want to get the 3rd number increment it and assign it again you can do following

var numberPattern = /\d+/g;
var string = $('#lang_file_1').attr('name');
var a = string.match( numberPattern );

$('#lang_file_1').attr('name','photo[[1,312,'+(++a[2])+']]');

https://jsfiddle.net/jzzL1d2r/3/

Sign up to request clarification or add additional context in comments.

4 Comments

Is it possible to extract the third element from the array, so that I can increment it?
yes using regex you can get the value, convert it into integer and increment it.
@rahulv check the edited answer, if this is what you want.
I have handled this in server side. Anyway thanks @Newinjava

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.