Jump to content

[SOLVED] pass variable to function


MDanz

Recommended Posts

<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

Link to comment
Share on other sites

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; ?>")' />

Link to comment
Share on other sites

 <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?

Link to comment
Share on other sites

 

 

   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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.