Jump to content

javascript adding inputs blank all :S


UnknownPlayer

Recommended Posts

I have this javascript function:

<script>
fields = 5;
function addInput() {
if (fields <= 15) {
	document.getElementById('inputs').innerHTML += "<input type='text' value='' name='igraci[]' /><br />";
	fields += 1;
} else {
	document.getElementById('inputs').innerHTML += "<br />15 je dozvoljeno.";
}
}
</script>

And this PHP Code:

<form action="klan.php?id='.$kid.'" method="post">
   <p>
   <div id="inputs">
   </div>
   <input class="button" type="button" onclick="addInput()" name="add" value="Dodaj jos igraca" />
   <br /><br />
   <input class="button" type="submit" name="sacuvaj" value="Posalji pozivnicu igracima" />
   </p>
</form>';

Now i have problem, when i click on button to add inputs, it add inputs, then i write in inputs some value, and when i wonna add more inputs, when click to add it remove all values on all inputs that was there :S

How can i just add input, not to remove value on previous inputs ?

Link to comment
https://forums.phpfreaks.com/topic/217350-javascript-adding-inputs-blank-all-s/
Share on other sites

You need to create an element and append it to document. You are currently rewiring the innerHTML.

 

Since your question is actually a javascript question and not a php question, moving this to the correct forum section...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.