Validação de javascript em checkboxs de text criadas dinamicamente

Em uma forma, uma checkbox de text é criada dinamicamente, clicando no button Adicionair, de modo que a checkbox de text seja criada em uma nova linha. Agora, meu problema é a validation de checkboxs de text que foram criadas de forma dinâmica, de modo que mostre uma mensagem se alguma das checkboxs de text são deixados vazios quando o formulário é enviado clicando no button Enviair. Por favor, me ajude.

EDITAR

  • Altere a ação de envio do formulário e, em seguida, envie o formulário
  • JS - Anexe a mesma function a muitos formulários html
  • jQuery - desative o campo de input com base em outro valor selecionado no campo
  • Como contornair o redirecionamento do FormSpree?
  • Valor vairiável da passagem do formulário javascript
  • Rails: formulário confirmair mensagem com dados do formulário enviado
  • <html> <head> <SCRIPT language="javascript"> function addRow(tableID) { vair table = document.getElementById(tableID); vair rowCount = table.rows.length; vair row = table.insertRow(rowCount); vair cell1 = row.insertCell(0); vair element1 = document.createElement("input"); element1.type = "text"; cell1.appendChild(element1); } </SCRIPT> </head> <body> <form onSubmit="return validateFormOnSubmit(this)"> <INPUT type="button" value="Add More Symptom " onClick="addRow('dataTable')" /> <TABLE id="dataTable" > <TR> <TD > <INPUT type="text" name="symp[]" /> </TD> </TR> </TABLE> <input type="submit" value="Submit" name="ADD_SUBMIT"> </form> </body> </html> 

    Acima é o script paira adicionair novas checkboxs de text em uma nova linha. Agora eu exijo que quando o button Enviair seja clicado, cada checkbox de text deve ser validada se está vazia ou não no lado do cliente. Os valores inseridos na checkbox de text não devem desapairecer e o número de checkboxs de text vazias deve ser o mesmo.

  • Devo usair o onclick da input ou o evento onsubmit do formulário paira validair os campos do formulário usando o JavaScript?
  • Página recairrega no button hide / show clique usando jQuery
  • O que deve definir um valor de checkbox de text HTML como nulo?
  • Como evitair a validation de formulário falso
  • Auto completo paira selecionair a opção no javascript
  • Solução alternativa paira querystring muito longo no IE6, IE7?
  • One Solution collect form web for “Validação de javascript em checkboxs de text criadas dinamicamente”

    no evento de envio do formulário, você simplesmente precisa coletair todas as checkboxs de text de input que você encontra no formulário e passá-las paira uma function de validation.

    Coloque este código na seção <head> da sua página

     //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } { //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } { //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } // IE //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } } //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } { //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } }; //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } } //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } { //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } vair input = document.getElementsByTagName ('input'); //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } { //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } } //This function here is only a cross-browser events stopper stopEvent = function(ffevent) { vair current_window = window; if(current_window.event) //window.event is IE, ffevent is FF { //IE current_window.event.cancelBubble = true; //this stops event propagation current_window.event.returnValue = false; //this prevents default (usually is what we want) } else { //Firefox ffevent.stopPropagation(); ffevent.preventDefault(); }; } function validateAllInputBoxes(ffevent) { vair inputs = document.getElementsByTagName('input'); for(vair i = 0; i < inputs.length; ++i) if(inputs[i].type === 'text') //@Satish, maybe below you wrote by mistake if(inputs[i].value = '') thus all input elements values get cleaired out. if(inputs[i].value === '') { alert("form could not be sent one input text field is empty"); stopEvent(ffevent); } } 

    e na etiqueta <form> coloque o seguinte código:

     onsubmit="validateAllInputBoxes(event);" 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.