can I write this code like this in a tempForm.php

  1. in  tmpForm.php
 


   public function funName()


   {


         some php code;


            ...


         echo "<script language="javascript">";


         echo "document.getElementById('response_$i').innerHTML ='$avail_flag$available';";	


	      echo "document.getElementById('checkbox_$i').innerHTML ='$if_check';";


    	  echo "</script>";


   }


      

(the above script has been generated at the top of the HTML page.)

I want to use this script to update some div's content dynamically, it does not work now.

in the view php file I call this function like this

   

the code (to generate a table)

                    …

              $funcName ;  //to change the above table content

  1. if I want to generate a checkbox in the above script should I use

  <input type="checkbox" name="name" value="value">

  instead of

  CHtml::checkBox("checkbox",true,array(…))

  1. Do you mean you have this function definition in your view file which is tmpForm.php? This looks weird to me. I also don't understand what you are trying to do here.

  2. Either way is fine.

  1. I do it in the model. and that function is a function in that model.

    in view I call this function to update partial content in a table dynamically.

I think putting those js code in a model is not a good idea. Model should be mainly dealing with data, while these js are for presentational purpose.

Your js also contain some PHP variables which I have no clue about. Since Yii has built-in support for jquery, it would be much easier to use jquery to update a div. For example:



$('#response_id').html('updated content');


Typo?  Function defined as "funName", called as "funcName".  ?

1.$('#response_id').html('updated content');

qiang , shall I put above code in model file (if like this ,there is an error.)when I need to update the table content

  1. how to post a picture in the question, how to use that "img" label       

                      ??

  1. This is a piece of js code. You can just embed it in your view code directly (with surrounding <script> tag).

  2. Use the file attach feature.

ok, thanks.

putting anything that is displayed in a controller or model violates MVC conventions, also down the road you might have to edit it and relearn where everything is.  ;)