MikeDXUNL Posted February 2, 2008 Share Posted February 2, 2008 var xmlHttp function readmore(str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="ajax/findnews.php"; url=url+"?newsid="+str; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("full").innerHTML=xmlHttp.responseText; } } i tried: ("full"+str) ("full"+str"") and I cant seem that line to equal full plus the str help please? Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/89019-include-var-in-getelementbyid/ Share on other sites More sharing options...
phpQuestioner Posted February 2, 2008 Share Posted February 2, 2008 What? - That's All I Can Say Your going to have to explain what your wanting or what your having problems with or errors or something. Link to comment https://forums.phpfreaks.com/topic/89019-include-var-in-getelementbyid/#findComment-455912 Share on other sites More sharing options...
MikeDXUNL Posted February 2, 2008 Author Share Posted February 2, 2008 in my html I have a line saying: <div id="full<?php echo $news['newsid']; ?>"> </div> say $news['newsid'] is 15 there is a link called Read More: <div id="readmore<?php echo $news['newsid'];?>"><a href="#" onClick="readmore('<?php echo $news['newsid']; ?>'); return false;">Read More</a></div> When they click Read More, It access the function and grabs Info from a PHP file. Then whatever is returned, should be placed in <div id="full<?php echo $news['newsid']; ?>"> </div> but I can't figure out in the JS: document.getElementById("full").innerHTML=xmlHttp.responseText; how to make full+str work so it will say "getElementByID("full15") technically Link to comment https://forums.phpfreaks.com/topic/89019-include-var-in-getelementbyid/#findComment-456099 Share on other sites More sharing options...
phpQuestioner Posted February 4, 2008 Share Posted February 4, 2008 You need to set the entire id with a parameter and then this will work. Example: <script language="javascript"> function readmore(from) { document.getElementById(from).innerHTML = xmlHttp.responseText; } </script> <div id="readmore<?php echo $news['newsid'];?>"><a href="#" onClick="readmore('<?php echo $news['newsid']; ?>'); return false;">Read More</a></div> Do something to this extent and I think it will work the way you want it to. Link to comment https://forums.phpfreaks.com/topic/89019-include-var-in-getelementbyid/#findComment-457370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.