Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP calling a java script with a variant

Status
Not open for further replies.

andyfresh

Technical User
Oct 4, 2005
33
0
0
GB
Hi,

Im currently writing a php script which has a hidden text box which contains a value pulled from a sql query which I know does return a result. When a check box is clicked a java script function is called which refreshes the page with the value in the hidden box becoming a variant.

The problem happens when the page refreshs and the variant doesnt appear. I wont display all the code just the important bit so please be ensured that I do have the closed form tag and things like that. Can any one point out the ovbious mistake I have probably made.

Code:
<script language="JavaScript" type="text/javascript">
function rss(){;
window.location = 'websitecomments.php?country=0&contractors=0&xy=0&sort=comments.EntryDate&rss=0&type=<? echo"$rss"; ?>'
}
</script>


<?
echo"<input type=hidden id=rss name=rss value=\"$row[0]\"><form>";
//begining of check box for rss
if ($row[10] == '1'){
echo'<input type="checkbox" value="$row[10]" checked name="RSS" onclick="rss()">"';
$type="c";
}elseif ($row[10] == '0') {
echo"<input type=\"checkbox\" value=\"$row[10]\" name=\"RSS\" onclick=\"rss()\">";
$type="uc";
}
//end of check box rss
?>
 
the issue is here
Code:
echo'<input type="checkbox" value="$row[10]" checked name="RSS" onclick="rss()">"';

you are using single quotes and therein variables are not expanded.

try instead
Code:
echo'<input type="checkbox" value="'.$row[10].'" checked name="RSS" onclick="rss()">"';
 
Hi thanks I tried and it does help however I have realised that its pulling in the $RSS variant from the address. So instead I have changed the code to the following however still no luck in pulling in the variant from the hidden text box.

Any ideas?

Andy

Code:
<script language="JavaScript" type="text/javascript">
function rss(){;
window.location = 'websitecomments.php?country=0&contractors=0&xy=0&sort=comments.EntryDate&rss=0&type=<? echo"$rssid"; ?>'
}
</script>


<?
echo"<input type=hidden id='rssid' name='rssid' value=\"$row[0]\"><form>";
//begining of check box for rss
if ($row[10] == '1'){
echo'<input type="checkbox" value="'.$row[10].'" checked name="RSS" onclick="rss()">"';
$type="c";
}elseif ($row[10] == '0') {
echo'<input type="checkbox" value="'.$row[10].'" name="RSS" onclick="rss()">';
$type="uc";
}
//end of check box rss
?>
 
i suspect you have not assigned a value to $rssid

try this instead
Code:
window.location = 'websitecomments.php?country=0&contractors=0&xy=0&sort=comments.EntryDate&rss=0&type=<?=$row[0]?>"; ?>'
}

to be honest - i can't see what use you are putting the hidden field to, though. perhaps you use it elsewhere in your code? it is outside of the form tags and therefore, of course, will not get submitted to the server. Also the rss() function does not use the input box value but rather is hardcoded by php.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top