0

Here is the plain HTML code which is working and want to move this to Yii framework .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1">
          <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

          <script language="javascript" type="text/javascript">
            $(function() {
                $.get("dist_list.html",
                    function(dist){
                    $("#sourceModels").html(dist);
                });
            });
        </script>
     </head>
    <body>
        <select id="sourceModels"  size="20" ></select>
    </body>
</html>

in the above code I am calling dist_list.html which is simple list

<option value='1'>AAA</option>
<option value='2'>BBB</option>
<option value='3'>CCC</option>
<option value='4'>DDD</option>
<option value='5'>EEE</option>
<option value='6'>FFF</option>

To Move this work to Yii framework , I moved java script code to a .js file and the dist_list.html copied to /components/js folder ( Both .js and html in the same folder)

in view I am calling registering the script using

Yii::app()->clientScript->registerScriptFile(
    Yii::app()->assetManager->publish(
        Yii::getPathOfAlias('application.components').'/js/models.js'
    ),
    CClientScript::POS_END
);

which is working fine . I even checked this by putting some alert statements java script

and using the below drop down list code

<?php echo CHtml::dropDownList("sourceModels", '',array(),array('class'=>'mandal','size'=>20) );?>

But the dropdown box is not getting the options from the html file which is getting called from Java script . I tried few paths changing when calling java script .

Could some one please help me on this ?

I am using the HTML just to load the options ( These options are fixed and even if there are changes max one ..two times) instead of database to save database calls . Any best approach you can suggest ? ( Don't want to copy them in the model ...)

Thank You

Regards

Kiran

1
  • seems like you are defeating the MVC structure of Yii so if you don't want to put the drop-down data in a model, you might as well simply fetch it with a php include() statement. Commented Aug 11, 2011 at 2:14

1 Answer 1

3
<?php echo CHtml::dropDownList("sourceModels", '',array(),array('class'=>'mandal','size'=>20,'id'=>'sorceModels') );?>

it seems like you doesn't specify the dropdown id,so the js can't find the Dom correct.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your response . That was problem and I corrected it . But still it is not finding the .html file
Ya it is looking for that file under /final/dist_list.html . Since I copied it to components/js it is not finding it .
Actually I believe the "sourceModels" id should get created with the CHtml::dropDownList function as by default the ID is the same as the name attribute.
@idg :- Thank You , but it is not getting created . explicitly we have to mention it in other attributes

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.