Как добавить одну форму с новой формой, а затем вернуться к старой форме в чат-боте в js - PullRequest
0 голосов
/ 27 октября 2019

Я пытаюсь добавить одну форму к другой форме в js, чтобы, когда у пользователя были параметры, он мог решить, какая из них ему нравится, и тогда она появится выше.

Я сделал функцию для создания параметров формы, но теперь я просто хочу, чтобы они отображались выше.

Я попытался добавить метод удаления к функции, и я попытался объединить метод удаления с функцией Создать хобби

, что я попробовал:

//remove text feild input
function removeTxtInput() {
  var textInput = document.getElementById("txtInput");
  alert("dis");
  textInput.attributes.removeNamedItem("type");
}

Я также попробовал это:

// document.getElementById('txtInput').onchange = function() {
//     var inputs = document.getElementsByTagName("input");
//     for (var i = 0; i < inputs.length; ++i)   
//     {
//         if(i < document.getElementById('combo').value){
//             inputs[i].style.display = 'inline';
//         } else {
//             inputs[i].style.display = 'none';
//         }
//     }


// }

скрипт:

let hobbies2 = ["hobby1","hobby2", "hobby3"];
function createHobbies() {
  //goes through each of the items in the array hobbies2. it will run 3 times and the 
  //variable hobby will be "hobby1", then "hobby2", then "hobby3"
  for(var hobby of hobbies2){
    document.getElementById("upDateText")
    form.appendChild(document.createElement("br"));
    var x = document.createElement("input");
    x.setAttribute("type", "checkbox");
    form.appendChild(x);
    var text = document.createElement("span");
    text.innerText = hobby;
    form.appendChild(text)
  }
}

var btnClick = function(text) {
  counter++;

  if (counter == 1) {
    document.getElementById("upDateText").innerText = "I am " + text + "!";
    let newElement = document.createElement("h1");
        newElement.style.textAlign = "right";
        newElement.innerText = "Hi " + text + "!";

    document.getElementById("upDateText").appendChild(newElement);
    createHobbies();


  } else if (counter == 2) {
    let newElement = document.createElement("h1");
    newElement.innerText = 'Im a big fan of' + hobbies + '.';
    let hobbies = 'your hobies here';
        newElement.style.textAlign = "right";    
    newElement.innerText =
      "that is so cool that you like" + hobbies + " can we be friends"; // your "hobies" is not defined!
    document.getElementById("upDateText").appendChild(newElement);
  } 

  else if (form.inputbox.value === "") {
    let newElement = document.createElement("h1");
    newElement.style.color = "red";
    newElement.innerText = "sorry bout that";
    document.getElementById("upDateText").appendChild(newElement);
  }
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...