Jump to content

Javascript with PHP


vidyashankara

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?
Link to comment
https://forums.phpfreaks.com/topic/15162-javascript-with-php/
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
Link to comment
https://forums.phpfreaks.com/topic/15162-javascript-with-php/#findComment-61147
Share on other sites

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.