Jump to content

Archived

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

vidyashankara

Javascript with PHP

Recommended Posts

I have this function on my php script..

[code]
echo "
function add() {
var i =1;
var txt = \"SEGID : <select name='segid[]'>";
for ($i=0; $i<count($atm); $i++) {
echo "<option value='PRO$atm[$i]'>PRO$atm[$i]";
}
echo "</select>\";
txt +=\" Residue : <select name='resi[]'> <option value=ASP>ASP <option value=GLU>GLU <option value=LYS>LYS </select>\";
txt +=\" Residue ID : <input type='text' name='resid[]' + i><br>\";
document.getElementById('prot').innerHTML += txt;
}";
[/code]

This function adds a set of text boxes everytime you click a button. The problem is, when you click on the button the second time, the values in the first set of text boxes gets reset and i gotta enter them again. is there anyway to prevent that?

Share this post


Link to post
Share on other sites
Hey there,

I notice this problem happens in Firefox, so here is how you can fix it.

add this to the top of the function
[code]
var div = document.createElement("DIV");
[/code]

replace this
document.getElementById('prot').innerHTML += txt;

with
[code]
div.innerHTML = txt;
document.getElementById('prot').appendChild(div);
[/code]

Let me know if this works

Share this post


Link to post
Share on other sites

×

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.