+ 1

How to pass value via form?

I want to pass a value via form which is generatet like this: for(var x=0; x<modulsArr.length ; x++){ var modulFormElement=document.createElement("FORM"); modulFormElement.action="lessons.php"; modulFormElement.methode="POST"; var modulInput=document.createElement("INPUT"); modulInput.value=modulsArr[x]; // gibt den wert des ausgewählten moduls weiter modulInput.name="modul"; modulInput.type="HIDDEN"; var p = document.createElement("p"); var div=document.createElement("div"); var ifra=document.createElement("iframe"); var node = document.createTextNode(modulsArr[x]+" Modul"); //adding the text to the paragraph p.appendChild(node); div.appendChild(p); div.setAttribute("class", "margin"); div.style.marginLeft="10%"; div.style.backgroundColor="white"; p.style.color="royalblue"; p.style.fontSize="16pt"; div._modulData= moduls[x]; div.appendChild(ifra); div.addEventListener("click", itemClickHandler, false); //fügt submit modulFormElement.appendChild(div); modulFormElement.appendChild(modulInput); el.appendChild(modulFormElement); }

12th Jan 2019, 10:17 PM
jack
jack - avatar
2 Réponses
+ 1
and than get it via: <?php $passModul=$_POST['modul']; ?> But its not working I get the message : Undefined index: modul in lessons.php on line 3
12th Jan 2019, 10:22 PM
jack
jack - avatar
+ 1
forgot to post the itemClickHandler function: var itemClickHandler= function(event){ // get element which event is attached (div) var element= event.currentTarget // get the custom attribute that refers to modul object var item= element._modulData element.parentNode.submit() event.stopPropagation() };
12th Jan 2019, 11:31 PM
jack
jack - avatar