Forum Moderators: coopster

Message Too Old, No Replies

javascript popwindow- getting values from form

         

electricocean

1:46 am on Jun 21, 2005 (gmt 0)

10+ Year Member



I am not sure about this but I have a javascript pop-up window that opens up specified html which is simple. What I want to do is have a form within the popup window and have php precess the form like so:

<script language="javascript">
<!--
function rateJoke(jtitle){
var w = window.open('',' +jtitle+ ','width=500,height=500,scrollbars=yes,resizable=yes');
var d = w.document;
d.write('<html><body><?php
is(isset($_POST['rate_submit'])){
$your_rating = $_POST['user_rate'];
$both_rates = $your_rating + $rating;
$rate = $both_rates / 2;
if($rate < 5){
$new_rate = $rate;
}
else{
echo "The number is greater that 5, try again";
}
$update_query = "UPDATE rating FROM jokes WHERE title='$title' VALUES ($new_rate)";//do stuff
}
?>
<p align="center"><form><?php
for($num = 1; $num <= 5; $num++){
echo "<input type="radio\" value="{$num}" /><img src="images/rate_star_{$num}.jpg" />";
}?><input type="submit" name="user_rate" value="Rate!" />
</body></html>');
d.close();
w.focus();
}
-->
</script>

This code has not been tested, but I was wondering if that would work or a better way to do it.

Thanks,
electricocean

lobo235

1:39 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Without testing the code I can tell you that you are on the right track. Mixing javascript and PHP can be confusing but just remember that javascript is client-side and PHP is server-side and you'll be fine.

Sathallrin

1:42 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



This would not work, as it would only display the php code to the user...
You would have to create a php page that the popup function will open and pass any peramaters that you need into it as a query string with the popup function.

lobo235

1:50 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I didn't notice that there were not php open and closing tags (<?php or?>) but if there were this could work. This could all be done on the same page (form could post to itself).

electricocean

10:43 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Well I tried it with javascript functions becuase I want to click on a link and that popup would hapen with values from the database. How could I turn it into php altogether?

electricocean