0

I was trying to change the value of a span with a specific id. Apparently, i am missing something. Here is the code

Javascript:

<script type="text/javascript">
function deis(deistir)
{

                 document.getElementById(deistir).innerHTML=2;

}

</script>

HTML:

<div class="arrow-up"  onClick="deis(<?php echo "cevap_".$id;?>)">
  </div>

    <span style="font-size:30px; color:#333;" id = "<?php echo "cevap_".$id;?>">

  &nbsp;&nbsp;1

 </span>

You may wonder why i am using php for id. It is because html segments in while loop so that $id keeps changing. Why is it not becoming 2? I want to alter the value of span from 1 to 2 when there is a click event.

1
  • If your JavaScript doesn't work. Don't show us the PHP. Determine if the output of the PHP is what you expect, and if it is then ask when the JavaScript doesn't work and show us the PHP output. If the output isn't what you expect, then you know you have a PHP problem and you have narrowed down what it is. Commented Sep 6, 2012 at 17:44

2 Answers 2

1

You are passing an (undefined) variable when you want a string literal.

deis(<?php echo "cevap_".$id;?>)"
//   ^  needs quotation marks ^
Sign up to request clarification or add additional context in comments.

Comments

0

Ok i did:)

I changed this:

<div class="arrow-up"  onClick="deis(<?php echo "cevap_".$id;?>)">

to that

<div class="arrow-up"  onClick="deis('<?php echo "cevap_".$id;?>')">

1 Comment

Yes, that is what I suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.