How could I display an alert from the controller class in CodeIgniter?
Typically you want to place any display content (such as HTML or Javascript) in a view, not in a controller. From the controller you load the view, and the view contains this code somewhere in it:
<script type="text/javascript">
alert('your alert');
</script>
See the CodeIgniter user_guide for more basics on how to structure your application:
http://www.codeigniter.com/user_guide
Anything you "print" using PHP's print, displays to the screen.
print "<script type=\"text/javascript\">alert('Some text');</script>";
Related
I am using Ajax for sending data on controller. Here I use TinyMCE editer in my popup form and I need to validate it. But here validation does not work properly in Magento.
Yes you should clarify more on this.
By the way wherever you have put your form in popup give it an ID like and in your form if you have text boxes then put class 'required-entry' in all required textboxes and you should have one submit button.
Then finally put this script after form :
<script type="text/javascript">
//<![CDATA[
var popupForm = new VarienForm('popupform', true);
//]]>
</script>
See how it goes.
I have a select.php page where the user selects a value from the dropdown. On selection the ajax code runs and information from ajax.php gets populated on the "display" div of the select.php page. Some of the information coming from ajax.php is in the form of textarea. But it gets displayed just as textarea, and not as tinymce editor. Even though I have called it in the head section of my page.
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea'
});
</script>
My problem is very similar to this: How do I initialize TinyMCE on a ajax loaded textarea in 4.x?
But I am not understanding the solution. Please help.
you can get data after that set data on tiny
success: function (data) {tinyMCE.get(data).getContent().replace('\'', "\’");},
Your call to tinymce.init() only acts on items in the DOM at the time the init() function is run. If you are adding additional <textarea> fields to the page later you need to run tinymce.init() after you add those elements to the DOM.
You can include a call to tinymce.init() in the same block of code that injects the <textarea> into the page directly after you inject the <textarea>.
Is it possible to add a javascript function to the add/edit forms of grocery_CRUD?
E.g. As a user is typing in a particular field when adding or editing a record I want to execute a javascript on the keydown event.
If so, how?
It is possible.
For example, you call the view like this:
$this->load->view('grocery_crud_view', $output);
In the beginning of the view (grocery_crud_view.php), you can add any javascript
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascrpt">
$("#field-code").keyup(function(){
alert("there is a keyup");
});
</script>
<?php
// The rest of default php code
?>
Most of the id of the grocery-CRUD view (if you use flexigrid theme) would be something like this : "field-your_field_name"
You can inspect with firebug or google-chrome developer tools to ensure it.
I use aspx c# as a viewengine within ASP.NET mvc project, I want to retrieve value from viewbag using javascript code.
I get all my viewbag related stuff from in a razor view like so ...
<script>
var myJSVariable = #Viewbag.MyViewbagVariable;
</script>
You could do the following for the MVC view engine pre-razor I believe
<script>
var myJSVariable = <%Viewbag.MyViewbagVariable%>;
</script>
<script type="text/javascript">
var yourVariable= #Html.Raw(Json.Encode(ViewBag.yourVariable))
</script>
If you are dealing with something simple like a string, you can save a viewbag in an data-* attribute of a HTML tag and use JavaScript to access that.
I am having a jquery ui dialog which takes html from a partial view from an asp.net mvc3 controller.
The jquery call is very simple:
$(result).appendTo("#vierge");
$("#vierge").dialog();
where the result of the partialView is as follow:
<p><span style="background-color: yellow; "> test test</span></p>
When I make an alert of the result I am having this:
But the dialog display nothing, for you what could be wrong with my code ?
Thanks alot for your help
ps: I am trying to load the dialog another way:
$(dialogDiv).load(href)
.dialog({
autoOpen: true,
});
the dialog open ok, but it display plain html code instead of the rendered html, such as this
You are missing $ sign in the first line, it should be like this:
$(result).appendTo("#vierge");
$("#vierge").dialog();
if you don't need to append result but only display it in a dialog box, you can use this code:
$('#vierge').html(result);
$("#vierge").dialog();