Forums

Javascript and Chronoform

angie_iu 04 Nov, 2009
I found this javascript online

var lista=''
var volte=0

function prepara(campi) {


volte++
if (volte>1) window.alert('non è possibile aggiungere i campi due volte; eventualmente aggiornare la pagina')
else  {
  lista+='<form name="form2">'
   for(i=1; i<=campi; i++) {
      lista+= ' Nome <input type=text name= "nome'+i+'" size=20> Cognome <input type=text name= "cognome'+i+'" size=20> Passaporto <input type=text name="passaporto'+i+'"size=40> Sistemazione (indicare se singola, doppia, tripla o quadrupla) <input type=text name= "sistemazione'+i+'" size=15><br> '
  }  
  lista+='<input type="submit" name="Invia" value="INVIA">   <input type="reset" name="Cancella" value="CANCELLA"></form>'
if(document.all)
{
document.all('spazio').innerHTML=lista;
}
else if(document.getElementById){
document.getElementById("spazio").innerHTML = lista
}
 else {
alert("il tuo browser non supporta questo metodo")
}
}
}



with this html code:


Quante persone parteciparanno alla gita? Inserisci il numero nella casella di testo e premi il tasto OK 
<form name="form1">
<input type="text" name="num" size=3>
<input type="button" name="bottone" value="OK" OnClick="javascript: prepara(document.form1.num.value)">
</form>
<span id="spazio"></span>


it works perfectly in a simple html page, but it doesn.t work in chronoform.
Any idea?

Thank you

Angela
GreyHead 05 Nov, 2009
Hi angie_iu,

Yes. You don't say what the code is or what you want it to do . . .

. . . but no code with <form> tags in it will work in ChronoForms as ChronoForms creates it's own form tags and HTML does not allow nested Form Tags.

Bob
nml375 05 Nov, 2009
Hi Angela,
From what I can read of the code, you are trying to create a dynamic form where you first specify the number of records to submit, and then generate that number of inputs of each "kind".

This can be done with ChronoForms and some javascripting, however this is a little more complex than your current form/code. There are a few threads since the last two or three months, I think, that covers how to dynamically add and remove form inputs in a way that ChronoForm can handle.

I'll see if I can't find any of those threads once I'm back on my workstation (instead of my WM6.1 device running Opera Mini). You could try searching the forum meanwhile, I'd start with the keywords "dynamic form"...

/Fredrik
angie_iu 05 Nov, 2009
Hi. I'm sorry for not saying what I wanted to do with that code.

It is an input text box in which I can insert a number(ex. 4), then click OK and the script generates exactly 4 forms (with some information: name, surname, address etc)

I supposed it was a tag problem...

I'll try searching in the forum, but I need something like "adding fields dinamically" ...

Please if you see something like this, just let me know.

Thanx bye bye
This topic is locked and no more replies can be posted.