Jump to content

Recommended Posts

[code]
echo "<head>

<script language=\"javascript\">";

echo "function add() {
var i = 1;
document.write(\"<input type=\"checkbox\" name=prot[] value=\"prot\"> Selection of Protonation of Residues:<br>SEGID : <select name=\"segid\">";

for ($i=0; $i<count($atm); $i++) {
echo"<option value=\"PRO$atm[$i]\">PRO$atm[$i]";
}

echo "</select>\")
document.write(\"Residue : <select name=resi> <option value=ASP>ASP <option value=GLU>GLU <option value=LYS>LYS </select>\")
document.write(\"Residue Id : <input type=\"text\" name=\"resid\" + i onClick=\"add()\"><br>\")
}";

echo "function cat(txt) {
alert(txt)
}";

echo "
</script>
</head>";


echo "<br>
<input type=checkbox name=prot[] value='prot'> Selection of Protonation of Residues:<br>";

echo "SEGID : <select name=segid> ";


for ($i=0; $i<count($atm); $i++) {
echo "<option value=PRO$atm[$i]>PRO$atm[$i]";
}

echo "</select>



Residue :
<select name=resi>
<option value=ASP>ASP
<option value=GLU>GLU
<option value=LYS>LYS
</select>
Residue Id : <input type=\"text\" name=\"resid\" onClick=\"cat('Hello')\"><p>";
[/code]

Hi, this is the code that i have right now. For some reason, i cant call the javascript function when i click on the text box. All the variable like $atm is defined earlier in the script. I added another function "cat" just to test if its working, but its not calling javascript at all. how do i do it?

Thanks
Vidyashankara
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/
Share on other sites

Hi

Perhaps I'm wrong, but doesn't
[code]
document.write(\"<input type=\"checkbox\"
[/code]

Essentially open the double quotes, and then close them for 'checkbox' and then open them again?

If that is the case, that is where you're problem is. Try using a single quote:

[code]document.write(\"<input type='checkbox'[/code]
and see what happens.

Cheers

M
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-57995
Share on other sites

[code]
<script language="javascript">
function add() {
var i = 1;
document.write("<input type='checkbox' name=prot[] value="prot"> Selection of Protonation of Residues:<br>SEGID : <select name="segid"><option value="PROA">PROA<option value="PROB">PROB<option value="PROC">PROC<option value="PROD">PROD</select>")
document.write("Residue : <select name=resi> <option value=ASP>ASP <option value=GLU>GLU <option value=LYS>LYS </select>")
document.write("Residue Id : <input type="text" name="resid" + i onClick="add()"><br>")
}
function cat(txt) {
alert(txt)
}
</script>
</head><br>
<input type=checkbox name=prot[] value='prot'> Selection of Protonation of Residues:<br>SEGID : <select name=segid> <option value=PROA>PROA<option value=PROB>PROB<option value=PROC>PROC<option value=PROD>PROD</select>


Residue :
<select name=resi>
<option value=ASP>ASP
<option value=GLU>GLU
<option value=LYS>LYS
</select>
Residue Id : <input type="text" name="resid" onClick="cat('Hello')"><p><br>

[/code]

Thats my generated Code. it seems alright to me.
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58004
Share on other sites

Ok, I removed the Function add() and the function cat() started to work alright, so There's something wrong with the first function.

The Generated Code
[code]

function add() {
var i = 1;
document.write("<input type='checkbox' name=prot[] value="prot"> Selection of Protonation of Residues:<br>SEGID : <select name="segid"><option value="PROA">PROA<option value="PROB">PROB<option value="PROC">PROC<option value="PROD">PROD</select>")
document.write("Residue : <select name=resi> <option value=ASP>ASP <option value=GLU>GLU <option value=LYS>LYS </select>")
document.write("Residue Id : <input type="text" name="resid" + i onClick="add()"><br>")
}

[/code]

PHP Code

[code]
function add() {
var i = 1;
document.write(\"<input type='checkbox' name=prot[] value=\"prot\"> Selection of Protonation of Residues:<br>SEGID : <select name=\"segid\">";

for ($i=0; $i<count($atm); $i++) {
echo" <option value=\"PRO$atm[$i]\">PRO$atm[$i]";
}

echo "</select>\")
document.write(\"Residue : <select name=resi> <option value=ASP>ASP <option value=GLU>GLU <option value=LYS>LYS </select>\")
document.write(\"Residue Id : <input type=\"text\" name=\"resid\" + i onClick=\"add()\"><br>\")
}";

[/code]
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58007
Share on other sites

Dude, you are amazing dude. Its working now!

thanks a lot :)

Just one little problem

in the following line, the onClick doesnt work, i tried /"add()/" and it still doesnt work. what do i do?
[code]
document.write(\"Residue Id : <input type='text' name='resid' onClick='add()'><br>\")
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58016
Share on other sites

the onclick='add()' doesn't work because you are using document.write()

document.write will over write the whole document (including your javascript code), you will need to use innerHTML to add the HTML to a div or another element

Here is a sample HTML and JavaScript code
[code]
<html>
<head>
<title></title>
<script language="javascript">
function add() {
var i = 1;
var txt = "<input type='checkbox' name=prot[] value='prot'> Selection of Protonation of Residues:<br>SEGID : <select name='segid'><option value='PROA'>PROA<option value='PROB'>PROB<option value='PROC'>PROC<option value='PROD'>PROD</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' onClick='add();'><br>";

document.getElementById('code').innerHTML += txt;

}
</script>
</head>
<body onload="add();">
<div id="code">

</div>
</body>
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58027
Share on other sites

Doesnt seem to work again now. I think i screwed up something.

[code]
echo "<head>

<script language=\"javascript\">";

echo "
function add() {
var txt = \"<input type='checkbox' name=prot[] value='prot'> Selection of Protonation of Residues:<br>SEGID : <select name='segid'>";
for ($i=0; $i<count($atm); $i++) {
echo "txt += <option value='PRO$atm[$i]'>PRO$atm[$i]";
}
echo "txt +=</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' onClick='add()'><br>\");
document.getElementById('code').innerHTML += txt;

}";


echo "
</script>
</head>";


echo "<br>
<input type=checkbox name=prot[] value='prot'> Selection of Protonation of Residues:<br>";

echo "SEGID : <select name=segid> ";


for ($i=0; $i<count($atm); $i++) {
echo "<option value=PRO$atm[$i]>PRO$atm[$i]";
}

echo "</select>



Residue :
<select name=resi>
<option value=ASP>ASP
<option value=GLU>GLU
<option value=LYS>LYS
</select>
Residue Id : <input type=\"text\" name=\"resid\" onClick=\"add()\"><p>
<body onload=\"add();\">
<div id=\"code\">";
[/code]

Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58039
Share on other sites

this is just HTML code, you need to make sure it's clean

for example, the <body onload=\"add();\"> shouldn't be in the middle of the page, you can just take it out (I added it just in the example)


the <div id=\"code\"> should have a close tag
[code]
<div id=\"code\"></div>
[/code]

You can put it anywhere you want (for example, before the <p>)
Link to comment
https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58045
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.