Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 05-04-2010, 04:37 PM Sweet Script I Made
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Wassup all, I'd like to share with you this script that I wrote. It's taken me about 20 minutes, but I think it's pretty cool (coming from a JS noob like myself)

Here, just copy and paste this into notepad, name it *.html, and open it in a browser. Don't use the source. The instructions and little generator is there also.

Oh yeah, the script is sort of a like a CMS auto-updating thing. I don't know how to describe it, take a look

Code:
<style type="text/css">
body {background:#000000;color:#ffffff;font-family:Arial;}
.editable {background:#888888;padding:10px;outline:none;border:2px dashed #ff0000;width:300px;margin:0px auto;}
h1 {text-align:center;}
</style>
<script type="text/javascript">
function updateit() {
var userInput = document.getElementById('demobox').innerHTML;
document.getElementById('examplefield').innerHTML = userInput;
document.getElementById('examplefield2').value = userInput;
}
setInterval("updateit()",1);
function updateit2() {
var toShow = document.getElementById('dS').value;
  if (toShow=="tag"){document.getElementById('userCode').innerHTML = "&lt;script type=\"text/javascript\"&gt;<br />function updateit() {<br />var userInput = document.getElementById('demobox').innerHTML;<br />document.getElementById('examplefield').innerHTML = userInput;<br />}<br />setInterval(\"updateit()\",1);<br />&lt;/script&gt;<br />&lt;div id=\"demobox\" class=\"editable\" onclick=\"javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;\" onblur=\"javascript: this.style.border='none';\">Click inside this Div and edit me!&lt;/div&gt;<br /><i>&lt;!---The following HTML is optional, displays contents of editable DIV---&gt;</i><br />&lt;b id=\"examplefield\"&gt;&lt;/b&gt;";}
  else if (toShow=="input"){document.getElementById('userCode').innerHTML = "&lt;script type=\"text/javascript\"&gt;<br />function updateit() {<br />var userInput = document.getElementById('demobox').innerHTML;<br />document.getElementById('examplefield2').value = userInput;<br />}<br />setInterval(\"updateit()\",1);<br />&lt;/script&gt;<br />&lt;div id=\"demobox\" class=\"editable\" onclick=\"javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;\" onblur=\"javascript: this.style.border='none';\">Click inside this Div and edit me!&lt;/div&gt;<br /><i>&lt;!---The following HTML is optional, displays contents of editable DIV---&gt;</i><br />&lt;input type=\"text\" id=\"examplefield2\" /&gt;";}
  else {document.getElementById('userCode').innerHTML = "Your JavaScript code will appear here!";}
}
</script>
<div style="width:90%;background:#111111;padding:30px;margin:0px auto;">
<h1>Demo</h1>
<div id="demobox" class="editable" onclick="javascript: this.contentEditable='true';this.style.border='2px solid #ff0000';void 0;" onblur="javascript: this.style.border='2px dashed #ff0000';">Click inside this Div and edit me!</div>
<h1>Usage Example</h1>
<p>For this to be actually USEFUL in a CMS, you can easily grab the contents of it by doing this:</p>
<em>Start typing in the above box and the content below will change automatically!</em>
<hr /><br />Regular Tag: <b id="examplefield"></b><br />
Input box (Stretched): <input type="text" style="width:700px;" id="examplefield2" />  <em>Try typing '&amp;' into the DIV above, it escapes it for you, too!</em>
<p>A good note is that you can also not let the user edit the input box, as you can see above.  Try to type in that &uarr;, you can't!  The input box refreshes itself every 0.001 (or something) seconds!</p>
<h1>Get the code!</h1>
<p>Want it?  You can have it!  Below is the relevant code you'll need to make this work for your site!</p>
<select id="dS">
<option value="none" disabled="disabled"> -- Select One -- </option>
<option value="tag">Regular Tag</option>
<option value="input">Input Box (Form)</option>
</select><input type="button" onclick="updateit2()" value="Get Code" />
<p id="userCode">Your JavaScript code will appear here!</p>
</div>
Hope you like it !
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-14-2010, 01:45 AM Re: Sweet Script I Made
Novice Talker

Posts: 4
Name: kevin
Trades: 0
Coool script, i tried as you said.......... thanks
clarkkent is offline
Reply With Quote
View Public Profile
 
Old 05-14-2010, 05:13 AM Re: Sweet Script I Made
Average Talker

Posts: 15
Trades: 0
Great job ... keep on the good work
__________________

Please login or register to view this content. Registration is FREE
AskTechGuy is offline
Reply With Quote
View Public Profile
 
Old 05-14-2010, 05:49 AM Re: Sweet Script I Made
Junior Talker

Posts: 1
Name: kenblueswell76
Trades: 0
Good work buddy. May be you are no more a noob!
kenblueswell76 is offline
Reply With Quote
View Public Profile
 
Old 05-14-2010, 06:50 AM Re: Sweet Script I Made
c69
c69's Avatar
Experienced Talker

Posts: 40
Name: Constantine
Trades: 0
Nice job for a noob )

Sidenote:
onblur="javascript: this.style.border='2px dashed #ff0000'
better be done like
onblur = "this.class = "inactive"
or even via unobtrusive javascript and attached events
c69 is offline
Reply With Quote
View Public Profile Visit c69's homepage!
 
Reply     « Reply to Sweet Script I Made
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35167 seconds with 12 queries