MDanz Posted September 12, 2009 Share Posted September 12, 2009 <img src='http://www.u-stack.com/quote.jpg' alt='Quote!' onclick='changeText($number)' /> <script type='text/javascript'> function changeText($number){ document.getElementById('reply').innerHTML = '$text'; } </script> <textarea name='reply' cols='50' rows='10' wrap='hard' id='reply'></textarea i tried this and its not working..i want the function to be determined by $number.. any help Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/ Share on other sites More sharing options...
RussellReal Posted September 12, 2009 Share Posted September 12, 2009 <script type='text/javascript'> function changeText(){ var xx = '<?php echo $text; ?>'; document.getElementById('reply').innerHTML = xx; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917011 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 um.. well you are trying to write php syntax in javascript.. and thats completely wrong. are you trying to pass a php variable into a javascript function? then you want to do something like this <script type='text/javascript'> function changeText(number){ document.getElementById('reply').innerHTML = number; } </script> and when you call the function <img src='http://www.u-stack.com/quote.jpg' alt='Quote!' onclick='changeText("<? echo $number; ?>")' /> Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917012 Share on other sites More sharing options...
MDanz Posted September 12, 2009 Author Share Posted September 12, 2009 <img src='http://www.u-stack.com/quote.jpg' alt='Quote!' onclick='changeText($number)' /> <script type='text/javascript'> function changeText(number){ document.getElementById('reply').innerHTML = number; } </script> i've got it working this way.. it displays the number in the text area... since this is a quote system.. $text = '[quote]'.$reply.'[/quote]'; i tried replacing number with $text, so it appears like this.. <img src='http://www.u-stack.com/quote.jpg' alt='Quote!' onclick='changeText($number)' /> <script type='text/javascript'> function changeText(number){ document.getElementById('reply').innerHTML = $text; } </script> but now it shows up blank in text area.. whats the correct way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917024 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 you can't use php variables in javascript that way. you can use russells way, or my way, but you are going to have to pass the php var into the javascript a different way. Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917028 Share on other sites More sharing options...
MDanz Posted September 12, 2009 Author Share Posted September 12, 2009 look at my website see the problem i'm having... press Q(quote), then scroll down to the bottom... http://www.u-stack.com/topic.php?id=44 its quoting the last result... :'( Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917033 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 post the relevant code. lets see what you got under the hood. Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917038 Share on other sites More sharing options...
MDanz Posted September 12, 2009 Author Share Posted September 12, 2009 while($row = mysql_fetch_assoc($result)) { $info = str_replace ("\r\n", '<br />',$row['info']); $hyperlink = $row['hyperlink']; $name = $row['name']; $username1 = $row['username']; $image = $row['image']; $number = $row['id']; $posted = $row['posted']; $reply = $row['reply']; $text = '[quote]'.$reply.'[/quote]'; $bb = new bbtags; $quote = $bb->replace($reply); echo "<div id='$number'><font color=grey font size=4px><strong> $username1</strong></font><br> <img src='$image' width='50px' height='50px'><br><br> <font color=white font size=3px>$quote</font><br></div>"; echo " <a href='report.php?id=$number'><img src='http://www.u-stack.com/report.jpg'></a> <img src='http://www.u-stack.com/quote.jpg' alt='Quote!' onclick='changeText($number)' /> <br><hr size='1'> <script type='text/javascript'> function changeText(number){ document.getElementById('reply').innerHTML = number; } </script> "; <textarea name='reply' cols='50' rows='10' wrap='hard' id='reply'></textarea><br> i thought a quote reply system would be easy.. i been stuck on this for hours lol Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917042 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 try changing this function changeText(number){ document.getElementById('reply').innerHTML = number; } to function changeText(number){ document.getElementById('reply').innerHTML = document.getElementById(number).innerHTML; } btw this is more a javascript problem than a php problem. but stick that function at the top of your page. Don't stick it in the loop because it will be posted a bunch of times and you will run into a same function error Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917045 Share on other sites More sharing options...
MDanz Posted September 12, 2009 Author Share Posted September 12, 2009 thx it works, even though its showing what i echoed in the textarea like.. <font font="" color="grey" size="4px"><strong> guest</strong></font><br> <img src="http://www.u-stack.com/guest.jpg" width="50px" height="50px"><br><br> <font font="" color="white" size="3px">hello14</font><br> btw i can only click once, i have to refresh to click again... is there a way around that.. thanks for the help.. Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917051 Share on other sites More sharing options...
mikesta707 Posted September 12, 2009 Share Posted September 12, 2009 it shows that because your div is wrapped around everything not just the quote. You want the div to be wrapped around just the quote, ie echo "<div id='$number'>$quote</div>"; and I dont know why you can only click once. did you remove the function from the loop? Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917056 Share on other sites More sharing options...
MDanz Posted September 12, 2009 Author Share Posted September 12, 2009 yep its working thx alot.. Quote Link to comment https://forums.phpfreaks.com/topic/173968-solved-pass-variable-to-function/#findComment-917058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.