How can I pass a php include call as a variable for javascript function? -
i have page use javascript innerhtml replace contents of element pseudo-static page.
the following code current content of element:
<?php $con = mysql_connect('***********', '******', '**********'); mysql_select_db(dbbmdmi); if ($con) { $sql = "select teamid, captain, countryid, arrdate, depdate teams"; $result = mysql_query($sql) or die(mysql_error()); $link = "<a id='" . $row["teamid"] . "' onclick='setteamid();replacecontentincontainer('content','replace_target6')'>edit</a>"; if ($result) { // output data of each row while($row = mysql_fetch_array($result, mysql_assoc)) { echo "captain: " . $row["captain"]. "<a id='" . $row["teamid"] . "' onclick=\"replacecontentincontainer2('content','<?php include 'scripts/editteam.php?teamid=" . $row["teamid"] . "'>')\">edit</a>;" . "</br>country: " . $row["countryid"]. "</br>dates: " . $row["arrdate"]. " - ". $row["depdate"]. "<br>"; } ?>
in onclick=\"replacecontentincontainer2('content','<?php include 'scripts/editteam.php?teamid=" . $row["teamid"] . "'>')
i'm trying pass php include "source" argument following function in original "container" page:
<script type="text/javascript"> function replacecontentincontainer2(target,source) { document.getelementbyid(target).innerhtml = source; } </script>
i keep getting error when click link:
teams.php:1syntaxerror: unexpected identifier 'scripts'. expected ')' end argument list.
basically, i'm trying pass $row_["teamid"] next page in address can call a
$_get` function.
any suggestions?
update:
after escaping single quotes in javascript function call, content of element replaced should be, except php include being rendered in new content html comment, rather run php.
escaped single quotes in onclick=\"replacecontentincontainer2('content','<?php include \'scripts/editteam.php?teamid=" . $row["teamid"] . "\'?>')\"
rendered html: <!--?php include 'scripts/editteam.php?teamid=kellog'?-->
that interesting idea. problem you're going run php going render string of <?php include... ?>
because php handles in , hands off. here you'll want do.
<!-- front-end.html--> <script type="text/javascript"> function replacecontentincontainer2(target,source) { document.getelementbyid(target).innerhtml = source; } function ajaxforhtml(url, callback) { var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (xhttp.readystate == 4 && xhttp.status == 200) { callback(xhttp.responsetext); } }; xhttp.open("get", "ajax_info.txt", true); xhttp.send(); } function clickaction(id) { ajaxforhtml('scripts/editteam.php?teamid=' + id, function(data) { replacecontentincontainer2('content', data); }); } </script> <?php $con = mysql_connect('***********', '******', '**********'); mysql_select_db(dbbmdmi); if ($con) { $sql = "select teamid, captain, countryid, arrdate, depdate teams"; $result = mysql_query($sql) or die(mysql_error()); $link = "<a id='" . $row["teamid"] . "' onclick='setteamid();replacecontentincontainer('content','replace_target6')'>edit</a>"; if ($result) { // output data of each row while($row = mysql_fetch_array($result, mysql_assoc)) { echo sprintf('captain: %s <a id="%d" onclick="clickaction(%d);">edit</a>;</br>country: %d</br>dates: %s - %s </br>', $row['captain'], $row['teamid'], $row['teamid'], $row["countryid"], $row["arrdate"], $row["depdate"] ); }
Comments
Post a Comment