View Full Version : Howto change <p></p> tags to <br> tags on pressing enter?
amper
06-22-2006, 09:43 PM
When pressing "enter" it closes </p> tag and opens new.
Is it possible to change this feature to include <br> tag without <p>?
Could not find this procedure in wysiwyg.js.
Thanks in advance.
djr33
06-22-2006, 10:07 PM
Please include a link to the DD script in question in your post. See this thread (http://www.dynamicdrive.com/forums/showthread.php?t=6) for the proper posting format when asking a question.
I think you're referring to the openWYSIWYG editor?
That code is pretty complex. I've changed a couple things, but it's hard to find stuff in it. I'll take a look.
amper
06-22-2006, 10:14 PM
Oops, sorry, of course it was about openWYSIWYG editor :)
djr33
06-22-2006, 10:27 PM
Meh. I dunno. That javascript is very complex.
It uses a function to write more calls to other functions on the page, at which point I'm lost.
Yeah, I'm looking through it and I can't find anything about converting to html. I don't think it's based on the event of the user hitting enter, but rather in some converting thing that the text is run though, where it converst a line break to <p>, but I still can't find it.
amper
06-22-2006, 10:45 PM
Write one more function to convert <p></p> to <br> on the fly? :)
amper
06-22-2006, 11:11 PM
Cause I think that that tags are included by browser in DHTML... :(
djr33
06-23-2006, 12:10 AM
I could write a function in php to do that easily; just not sure how to do so in JS.
<?php
//assume $text is the final text:
$text = str_replace('<p>','<br>',$text);
$text = str_replace('</p>','',$text);
//now $text has <br> instead of <p></p>
?>
All you'd need is the function to do a string replace in javascript (surely there is one), and call it onSubmit in the form tag.
Also, in dreamweaver, if you press shift+enter, it inserts a <br> instead of <p> tag. I was thinking this script worked in the same way, so I tried it out.
But... whatever I did, I just got <br> tags... no <p> tags. I don't get it.
Now... technically, since I'm on a mac, I'm pressing return, but I don't know if that is actually different in terms of javascript. It still enters a line break, so it would be seen in the same way by the JS.
Anyway.... any ideas why we're getting different things?
amper
06-27-2006, 11:58 AM
In IE it works perfectly, on Shift+Enter it adds <BR> tag, on pure Enter it adds <P></P> tags.
Is there any way to switch the behaviour? On pure Enter - <BR>, on Shift+Enter <P>...? Or just emulate the pressed shift button...
djr33
06-27-2006, 07:14 PM
Good question.
The issue is finding the coding, not changing it. If you find where it controls that in the JS, should be VERY easy to switch. But I can't find it...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.