Re: passing variables from php to javascript

From: Date: Tue, 11 Jul 2000 13:40:48 +0000
Subject: Re: passing variables from php to javascript
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5914@lists.php.net to get a copy of this message
I use the attached javascript function to get the values of a form, and then open a new window that is about the size of an alert box. It takes the form inputs and build an http get request that php can use in the new windows. A sort of pseudo alert box. Hope this helps. Robert Zwink ----- Original Message ----- From: "B. Keith Murphy" <bmurphy@maximumhost.net> To: <php-general@lists.php.net> Sent: Tuesday, July 11, 2000 8:06 AM Subject: [PHP] passing variables from php to javascript I have been working on integrating a small javascript function in with php. I am including the code. Everything works as is, but I also need to pass a variable from the html/php into the javascript function to print out the string length of the text post. Please let me know how this can be done. I have included the code below for suggestions. thanks Keith <? ?> <DEFANGED_script language="javascript"> function string_length() { string_count = "4"; alert ("The sequence is " +string_count+ " long"); return; } </script> <form action="mailto.php3" method="post"> <table border="0"> <? for ($i = 1; $i <= $number_of_oligos; $i++): ?> <tr> <td> <? echo ("sequence $i") ?> </td> <td> <input type="text" name="sequence[]"><br><br> </td> <td> <input type="button" name="length" value="How long is my sequence?" DEFANGED_OnClick="string_length()" <br><br></td> </tr> <? endfor ?> <tr> <td><input type=submit> </tr> </table> </form>

function thanksPage() { var to_email = document.forms[0].elements[0].value; var to_name = document.forms[0].elements[1].value; var from_email = document.forms[0].elements[2].value; var from_name = document.forms[0].elements[3].value; var filename = document.forms[0].elements[4].value; var href = document.location.href; var version = navigator.appVersion; if (version.indexOf("MSIE") != -1) { window.open("send_email.phtml?to_email=" + to_email + "&to_name=" + to_name + "&template%5BFROM_EMAIL%5D=" + from_email + "&template%5BFROM_NAME%5D=" + from_name + "&filename=" + filename + "&href=" + href, "normal_spec", "HEIGHT=300, WIDTH=370"); }else{ window.open("send_email.phtml?to_email=" + to_email + "&to_name=" + to_name + "&template%5BFROM_EMAIL%5D=" + from_email + "&template%5BFROM_NAME%5D=" + from_name + "&filename=" + filename + "&href=" + href, "normal_spec", "HEIGHT=300,WIDTH=370,alwaysRaised"); } }
« previous php.general (#5914) next »