I recently asked a question: Deleting a line when clicking a button

This is the problem: There is such a code

<input value="lalala;mememe" id="1"> 

And there is one more

 <input value=";mememe" id="2"> 

How do I make sure that the line specified in input id = "2" is deleted from input id = "1"

  • five
    on the same principle as in the first question. you programmer. think about it and yes, id should not begin with a number. - mountpoint
  • okay, think about it - Yuri
  • Delete something for what event you want? - pvkovalev
  • @mountpoint "IDs should not start with a number" - this is not true for html5 - Semushin Sergey

1 answer 1

Removed by the same principle:

 document.querySelector('button').onclick = function() { var a1 = document.getElementById('a1'), a2 = document.getElementById('a2'); var reg = new RegExp(a2.value, 'i'); a1.value = a1.value.replace(reg, ''); }; 
 <input value="lalala;mememe" id="a1"> <input value=";mememe" id="a2"> <button>Заменить</button> 

Note: id should not begin with a number

  • Note 2: but it will also give you a figure :) - Qwertiy
  • new RegExp(a2.value, 'i') you don’t need to do this — who will be new RegExp(a2.value, 'i') special characters? And in general, and what have onload? To do such things in onload is some kind of nonsense. - Qwertiy
  • @Qwertiy, show your solution :) - Yuri
  • But I didn’t understand the essence of the question) - Qwertiy
  • @Qwertiy, the point was to remove the text from the first input, which is specified in the second - Yuri