0

i have a textbox1 which input by user and textbox2 for user to input numbers which can automatically generate textbox1 value into multiple string such as example below:

Txtbox1 = ABC12345
Txtbox2 = 3

Result will be

ABC12345-1
ABC12345-2
ABC12345-3
2
  • only get value from txtbox and try to use an button to triggle when txtbox2 is input Commented Oct 17, 2017 at 6:11
  • this forum is not to discuss logic, rather its to discuss syntax or other such problems Commented Oct 17, 2017 at 6:12

2 Answers 2

2

You can try using something like this below, but kinda hard to make it 100% as you want, since you haven't shown any HTML.

$("[id^=Txbox]").keyup(function() {
  var empty = $("[id^=Txbox]").filter(function() {
    return $.trim($(this).val()).length == 0
  }).length == 0;
  if (empty) {
    var str = $("#Txbox1").val();
    var number = $("#Txbox2").val();
    var arr = [];
    for (i = 0; i < number; i++) {
      arr.push(str + "-" + i)
    }

    console.log(arr)
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="Txbox1" />
<input id="Txbox2" type="number" />

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

Comments

0

You can just use button and apply click event.

function getString() {
  var finalString = [];
  var t = $("#textbox1").val()
  var n = $("#textbox2").val();
  if (t.toString().trim() != "") {
    for (i = 0; i < n; i++) {
      finalString.push(t + "-" + (i + 1))
    }
  }
  console.log(finalString)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Text : <input type="text" id="textbox1"><br><br> Number : <input type="text" id="textbox2">

<button type="button" onClick="getString()" id="textbox1">Get</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.