Tell me how to solve this problem:?

Create 3 blocks with id: id_1, id_2 and id_3.

Create a text field in which the user must enter the number 1, 2 or 3.

Create a "Delete" button.

After clicking on the "Delete" button, hide through hide () in the jQuery block with id = id_num_number. For example, if the user entered 2, then the block id_2 should disappear

Solve using jquery. Cheto generally can not figure out how to do?

p / s

<div id="id_1" onclick="$('#test').hide()">1111111</div> <div id="id_2" onclick="$('#test').hide()">2222222</div> <div id="id_3" onclick="$('#test').hide()">3333333</div> <input type="text" value="" id="text"/> <input type="submit" value="Удалить" id="button" onclick=" var element=$('text'); var text = element.val(); alert(text); "/> 

That's what, I can not get the value of the text field by clicking on the field!

  • @duddeniska, According to the rules of the forum, questions should not be limited to the decision or the completion of student assignments. Please clarify what you have done yourself and what did not work out. - Zhukov Roman
  • onclick = "alert ($ ('text'). val ())" And make the type of the button button - Vladislav Pyatkov

3 answers 3

http://jsfiddle.net/XDM7C/

 <div class="box" id="id_1"></div> <div class="box" id="id_2"></div> <div class="box" id="id_3"></div> <input type="text" id="it"> <input type="button" value="remove" onclick="document.getElementById('id_' + it.value).style.display = 'none'"> 

    http://jsfiddle.net/m6mjK/1/

    - Well done, Ivanov! Sit down, five!

    - Well, you, Pal Palych, wrote in 2 minutes =)))

    • one
      @mountpoint, No, I had to cram everything in onclick: <input type = "submit" value = "Delete" id = "button" onclick = '(function () {var val = $ ("input [type = text]" ) .val (); if (isNaN (val)) {alert ("Enter Number"); return;} $ ("# id_" + val) .hide (1000);}) () '/> - Vladislav Pyatkov
    • >> it was not necessary to stuff everything in onclick, I did not understand you. maybe you missed a comma somewhere?)) - mountpoint
    • Yeah, added a comma. - Vladislav Pyatkov
     <div id="bl1">Блок 1</div> <div id="bl2">Блок 2</div> <div id="bl3">Блок 3</div> <input type="number" min="1" max="3" step="1" name="nomer" id="nomer"> <input type="button" name="btn" value="Видалити" onclick="$('#bl' + $('#nomer').val()).hide();"> 
    • Brrr .. Use onclick with jQuery ... - Qwertiy