vidyashankara Posted July 14, 2006 Share Posted July 14, 2006 [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?ThanksVidyashankara Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/ Share on other sites More sharing options...
MilesWilson Posted July 14, 2006 Share Posted July 14, 2006 HiPerhaps 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.CheersM Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-57995 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 No change :( I tried that at first, because it dint work, i changed it to \"checkbox\" Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-57996 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2006 Share Posted July 14, 2006 Look at your generated source to see if the Javascript is being generated correctly.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-57999 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58004 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58007 Share on other sites More sharing options...
nogray Posted July 14, 2006 Share Posted July 14, 2006 if your document.write there is a value="prot">change all the " to ' inside the document.write and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58010 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 Dude, you are amazing dude. Its working now!thanks a lot :) Just one little problemin 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] Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58016 Share on other sites More sharing options...
Oldiesmann Posted July 14, 2006 Share Posted July 14, 2006 You want \"add()\" or 'add()', not /"add()/". Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58018 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 \"add()\" doesnt work. Thats what i tried, that last one was a typo, sorry. Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58019 Share on other sites More sharing options...
nogray Posted July 14, 2006 Share Posted July 14, 2006 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 elementHere 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] Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58027 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58039 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 I got it! Just some stupid mistakes.Now, when i click the text box, The 3 boxes show up right at the bottom of the document, can i make it show up right after the text box? Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58043 Share on other sites More sharing options...
nogray Posted July 14, 2006 Share Posted July 14, 2006 this is just HTML code, you need to make sure it's cleanfor 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>) Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58045 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Author Share Posted July 14, 2006 nogray.. you rock! Thanks a lot!and just one more question, now we have so many text boxes, how do i read the data submitted in this box? The script reads only the value in the last box. should i put the name of the form as resid[] ? instead of just resid? Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58047 Share on other sites More sharing options...
nogray Posted July 14, 2006 Share Posted July 14, 2006 resid[] will work and it'll pass an array to you php file. Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58114 Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 yes, you'll need to give the inputs an array name if you want to process multiple inputs. Quote Link to comment https://forums.phpfreaks.com/topic/14597-javascript-with-php/#findComment-58120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.