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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.