...

View Full Version : javascript and php



cgibie
02-03-2007, 12:22 PM
Hi guys, is there a way I can making javascript and php mixed together? I could not get the code below to work at all.



<script>
var rand_value = document.entry.random.value;
rand_value = <?php $rand_value;
$img_code = md5($rand_value);
if ($img_code != $_SESSION['image_random_value'])?>
{
alert("Wrong Image Code!")
entry.random.focus();
return false;
}
</script>

mlseim
02-03-2007, 01:50 PM
Try it now ... by moving the closing PHP ?>
and an echo ... and a few other small changes.

<script>
var rand_value = document.entry.random.value;
rand_value = <?=$rand_value?>;
<?php
$img_code = md5($rand_value);
if ($img_code != $_SESSION['image_random_value'])
{
echo"
alert(\"Wrong Image Code!\")
entry.random.focus();
return false;
";
}
?>
</script>


.

cgibie
02-03-2007, 09:32 PM
var rand_value = document.entry.random.value;
rand_value = <?=$rand_value?>;
<?php
//session_start();
$img_code = md5($rand_value);
if ($img_code != $_SESSION['image_random_value'])
{
echo"alert(\"Wrong Image Code!\")
entry.random.focus();
return false;";
}
?>


Still not working, the problem seems to be this line rand_value = <?=$rand_value?>;

When I comment out it, my code executed but always gave me "wrong image code" error msg even though I typed in correct one. I tried to remove the "=" sign from it rand_value <?=$rand_value?>; or rand_value <?=$rand_value?>; still is not working.

cgibie
02-04-2007, 02:48 AM
hello?

Mwnciau
02-04-2007, 03:40 AM
Tried <?php echo $rand_value; ?> ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum