imgrooot Posted November 26, 2015 Share Posted November 26, 2015 You know when you type text into a form input and it automatically types the same text in another div? Well I am trying to do the same thing but instead show the same text value from the div 1 to div 2. Here is my code. It works with the input text field but not with the textarea. Can you tell me why? <input type="text" name="title" id="title" value="" maxlength="55" /> <textarea name="details" id="details" value="" maxlength="160" ></textarea> <!-- Values show up in these inputs --> <input type="text" name="seo_page_title" id="seo_page_title" value="" maxlength="55" /> <textarea name="seo_page_description" id="seo_page_description" maxlength="160" ></textarea> <script> $('#title').on("input", function() { var dInput = this.value; console.log(dInput); $('#seo_page_title').val(dInput); }); $('#details').on("input", function() { var dInput = this.value; console.log(dInput); $('#seo_page_description').val(dInput); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/ Share on other sites More sharing options...
Jacques1 Posted November 26, 2015 Share Posted November 26, 2015 Works fine for me in Firefox 42 and Chromium: https://jsfiddle.net/mmm69xfo/ Which browser are you using? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527190 Share on other sites More sharing options...
imgrooot Posted November 26, 2015 Author Share Posted November 26, 2015 Works fine for me in Firefox 42 and Chromium: https://jsfiddle.net/mmm69xfo/ Which browser are you using? Oh I see why it wasn't working. I am also using "ckeditor(http://ckeditor.com/)" in the textarea field. Once I removed it, it worked. Though I really need to use that editor. How can I make it work with having that editor as well? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527204 Share on other sites More sharing options...
Ch0cu3r Posted November 26, 2015 Share Posted November 26, 2015 You need to use CKEditors setData method in order set the value for the editor Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527214 Share on other sites More sharing options...
imgrooot Posted November 26, 2015 Author Share Posted November 26, 2015 You need to use CKEditors setData method in order set the value for the editor Can you please show me how I would use the "setData method" within my code above? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527216 Share on other sites More sharing options...
Ch0cu3r Posted November 26, 2015 Share Posted November 26, 2015 Modifying Jacques1 code example https://jsfiddle.net/mmm69xfo/1/ Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527218 Share on other sites More sharing options...
imgrooot Posted November 26, 2015 Author Share Posted November 26, 2015 Modifying Jacques1 code example https://jsfiddle.net/mmm69xfo/1/ That works, but I think my original question might have been a bit misunderstood. I already have the ckeditor in the details textarea. I don't have the ckeditor in the seo description textarea and I don't need one either. Your example works, but it's the opposite of what I am looking to do. Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527220 Share on other sites More sharing options...
imgrooot Posted November 27, 2015 Author Share Posted November 27, 2015 Modifying Jacques1 code example https://jsfiddle.net/mmm69xfo/1/ So can you show me the reverse of what you did? Like switch the "details" with "seo_page_description"? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527226 Share on other sites More sharing options...
Ch0cu3r Posted November 27, 2015 Share Posted November 27, 2015 (edited) Your example works, but it's the opposite of what I am looking to do. In that case you want to use CKEditors on change event. Then use editor.getData to get contents of the editor setting the the value for seo_page_description textarea using jquerys .val() method Updated example https://jsfiddle.net/mmm69xfo/2/ Edited November 27, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527232 Share on other sites More sharing options...
imgrooot Posted November 27, 2015 Author Share Posted November 27, 2015 In that case you want to use CKEditors on change event. Then use editor.getData to get contents of the editor setting the the value for seo_page_description textarea using jquerys .val() method Updated example https://jsfiddle.net/mmm69xfo/2/ Perfect! That's what I was looking for. One minor thing. Is it possible to remove/hide the "<p>" tag that shows up in the seo_page_description textarea? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527235 Share on other sites More sharing options...
Solution Ch0cu3r Posted November 27, 2015 Solution Share Posted November 27, 2015 So you only want plain text to be inserted into seo_page_description textarea, stripping out all html tags returned by CKEditor? In that case use JQuery.text method $('#seo_page_description').val($(evt.editor.getData()).text()); Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527239 Share on other sites More sharing options...
imgrooot Posted November 27, 2015 Author Share Posted November 27, 2015 So you only want plain text to be inserted into seo_page_description textarea, stripping out all html tags returned by CKEditor? In that case use JQuery.text method $('#seo_page_description').val($(evt.editor.getData()).text()); Yes since it's the meta title and description, I only require the plain text. Your method works perfectly now. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527246 Share on other sites More sharing options...
Ch0cu3r Posted November 27, 2015 Share Posted November 27, 2015 So why the need for CKEditor if you only need plain text? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527247 Share on other sites More sharing options...
imgrooot Posted November 28, 2015 Author Share Posted November 28, 2015 So why the need for CKEditor if you only need plain text? Basically the "title" and "details" inputs are for showing text on a page. I need CKEditor for the "details" input so that the user can modify the text. That seo_description input is suppose to have the same value as the "details" input. So instead of making the user write the same text again in the seo_page_description textarea, I am having it so that it automatically adds to it from the "details" input. And since seo_page_description is only going to showing in the meta details in the header, I only need it in plain text. One thing I noticed. The textarea that has the CKeditor; it inserts the text(with tags) into the MySql database fine. I can also retrive it from the database fine. It includes all the html tags. However the text is not styled by default. I have to style the tags with css for the text to appear as the user has intended in the Ckeditor. Is this normal? Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527252 Share on other sites More sharing options...
Ch0cu3r Posted November 28, 2015 Share Posted November 28, 2015 CKEditor uses the contents.css file distributed by CKEditor for styling the contents in the editor. Make sure you are also including this stylesheet in your pages. If you want the editor to use your stylesheet then use the stylesheet plugin Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527258 Share on other sites More sharing options...
imgrooot Posted November 28, 2015 Author Share Posted November 28, 2015 CKEditor uses the contents.css file distributed by CKEditor for styling the contents in the editor. Make sure you are also including this stylesheet in your pages. If you want the editor to use your stylesheet then use the stylesheet plugin Oh I see. I will give it a shot. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/299583-quick-help-regarding-showing-typed-text-from-one-input-to-another-check-out-this-code/#findComment-1527268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.