...

View Full Version : Form information fetching problem



bdgarfield
07-22-2010, 09:01 PM
Hello everyone,

I've got a problem while trying to fetch some informations from multiple forms in the same page.
What I'm trying to do with this code is fetching informations from the multiple forms on my page and checking if the information is the information I need.
If so, I take this information and add it into a javascript generated form that I submit once every form in the page have been taken care of.

It's the only way I found to 'submit' multiple forms at the same time.

Everything was fine until I decided to give the user the option to add more forms on the page by clicking on a button (the form is then generated by javascript and appended on the page).

There seems to be a problem when checking these particular forms, the script doesn't seem to recognize the value of the radio button (wich is add_question_faq) and never ever enters in this case.
case "add_question_faq":
alert ("pourquoi, ho, pourquoi")
if (mesForms[cpt].question.value=="" || mesForms[cpt].answer.value==""){
chaineModif+="StopSendRightNow"
}
break;

Except when the commentarised

//for (h=0;h<mesForms[cpt].elements.length;h++){
//alert (mesForms[cpt].elements[h].name)
//}
ain't commentarised.

Any Idea why a simple alert changes the behavior of the function?


Here's the said function:


function select_forms_faq(){

var chaineModif=""
var mesFormsModif=new Array();
var mesForms=document.getElementsByTagName("form");

for (cpt=0;cpt<mesForms.length;cpt++){

//for (h=0;h<mesForms[cpt].elements.length;h++){
//alert (mesForms[cpt].elements[h].name)
//}

if (mesForms[cpt].action.length!=0 && mesForms[cpt].action.length!=undefined){

for (k=0;k<mesForms[cpt].action.length;k++){

if (mesForms[cpt].action[k].checked==true){

switch (mesForms[cpt].action[k].value){

case "delete":
chaineModif+="<input type=\'text\' name=\'delete_"+mesForms[cpt].id_question.value+"\' value=\'"+mesForms[cpt].id_question.value+"\' />";
break;
case "save_changes_question":
chaineModif+="<input type=\'text\' name=\'update_question_faq_"+mesForms[cpt].id_question.value+"\' value=\'id"+mesForms[cpt].id_question.value+"question"+mesForms[cpt].question.value+"answer"+mesForms[cpt].answer.value+"\' />"
break;
case "save_changes_cat":
chaineModif+="<input type=\'text\' name=\'update_cat_faq_\' value=\'id"+mesForms[cpt].id_cat.value+"category"+mesForms[cpt].cat.value+"\' />"
break;
case "add_question_faq":
alert ("pourquoi, ho, pourquoi")
if (mesForms[cpt].question.value=="" || mesForms[cpt].answer.value==""){
chaineModif+="StopSendRightNow"
}
break;
}
}
}
}
}
if (chaineModif!="" && chaineModif.indexOf("StopSendRightNow")==-1){
var formFinal=document.createElement("form")
with(formFinal){
method="POST"
action=""
name="formFinal"
id="formFinal"
style.display="none"
}
chaineModif+="<input type=\'hidden\' name=\'submit_changes_faq\' value=\'submit_changes_faq\' />"
document.getElementById("wpbody-content").appendChild(formFinal)
document.getElementById("formFinal").innerHTML=chaineModif
formFinal.submit();
return false
}
else{
return false
}
}

bdgarfield
07-22-2010, 09:44 PM
The code also works if I wait something like 5 minutes.

What's going on there?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum