Jump to content

Rain Lover

  • Posts

  • Joined

  • Last visited

About Rain Lover

  • Birthday 02/17/1979

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Isfahan, Iran
  • Interests
    sports, music, Internet, reading, and travel

Recent Profile Visitors

2,029 profile views

Rain Lover's Achievements


Newbie (1/7)



  1. As you see the outline is collapsed in the following sample: var input = document.getElementById('input'); var output = document.getElementById('output'); input.addEventListener('input', function() { output.value = input.value; }); output { display: block; font: 20px Arial; outline: 1px solid green; } <input id="input"> <output id="output"></output> DEMO How can I prevent it? Do I need to give the output a fixed height? If so, what value should I give to the height if I want it to be just as high as the text height — not an arbitrary number? Is there a cross-browser solution?
  2. Scenario Every semester my students need to take at least one test. The following form gives the right average grade of a student: <!DOCTYPE html> <html lang="en"> <head> <title>Average Grade</title> </head> <body> <form> Math: <input type="number" id="test1"> <input type="number" id="test2"> <input type="number" id="test3"> <output id="average"></output> <br> <input type="button" value="Calculate" id="calcBtn"> </form> <script> document.getElementById('calcBtn').addEventListener('click', function() { var test1 = document.getElementById('test1').value; var test2 = document.getElementById('test2').value; var test3 = document.getElementById('test3').value; var average = document.getElementById('average'); average.value = (Number(test1)+Number(test2)+Number(test3)) / 3; }); </script> </body> </html> DEMO The problem is it works right only if all the fields are edited. If the student doesn't take some tests, the average grade won't show the right value. I know it's because of dividing by the fixed number 3 when it calculates the average grade: average.value = (Number(test1)+Number(test2)+Number(test3)) / 3; Question What is a simple approach to get the number of changed input fields?
  3. Steps to reproduce the issue: In your browser Settings select Continue where you/I left off under On startup. Navigate to the demo. Check the checkbox. Edit the text. Close your browser and reopen it. Or duplicate/clone the tab. Now as you see the checkbox is checked, but the textarea isn't colored. I tried it in the latest version of Chrome and Opera in Windows 10. I'm not sure about Safari, but it probably behaves the same way. Questions: Why does it happen? What's a cross-browser solution?
  4. Consider this: <input type="file" id="filePicker"> <script> document.getElementById('filePicker').onchange = function() { alert('Hi!'); }; </script> Even if you choose the same file and the filePicker value doesn't change, you'll see the alert box in Firefox. Any solutions?
  5. Yes, that seems to be the problem. Then I need to put my question this way: How to reload the parent frame that's located on a different frame?
  6. Sample parent code: <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Parent</title></head><body><iframe src="https://dl.dropboxusercontent.com/u/4017788/Labs/child.html" width="200" height="100"></iframe></body></html> See it in action: https://googledrive.com/host/0B5jOXzxlxbMhYVF3b0lubjlDWm8/parent.html Sample child code: <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Child</title></head><body><button onclick="myFunction();">Try it!</button><script>function myFunction() {parent.location.reload();}</script></body></html> I have tried many methods offered in similar questions to no avail, such as: window.parent.location.reload(); top.location.reload(); etc. What am I missing and what's the right approach?
  7. Thanks for the answer, but: I don't know how to do it using cURL. Would you mind providing a snippet to use as a template? Doesn't it break the layout when the target page has non-absolute URLs and relative links?
  8. When I embed an external HTTP iframe into my HTTPS page, I get a mixed content error message: <iframe src="http://www.example.com"></iframe> To work around this limitation I'd like to echo the external page from my own domain. How should I do that? Thanks!
  9. Sample form: <!DOCTYPE html><html><head><title></title><style type="text/css">* {font:13px arial; color:white;}body {background:black;}label {display:inline-block; width:50px;}input, textarea {margin:0; border:1px solid red; padding:0; background:green;}textarea {width:300px; height:100px;}</style></head><body><form action="#"><div><label for="entry_0">Name</label><input type="text" id="entry_0"></div><div><label for="entry_1">Email</label><input type="text" id="entry_1"></div><div><label for="entry_2">URL</label><input type="text" id="entry_2"></div><div id="parent"><textarea id="entry_3"></textarea></div><div><input type="submit" value="Submit"></div></form></body></html> I'd like to remove/hide the textarea scrollbar as it doesn't match my form style. I know I can use jQuery plugins to style the scrollbar, but they don't work reliably across different browsers/systems.To hide the scrollbar I can use textarea {width:300px; height:100px; overflow:hidden;}, but it completely stops Firefox scrolling through mouse and keyboard.I also tried the following workaround: #parent {width:284px; height:102px; overflow:hidden;}textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;} It should work accurately if I add some script to calculate the parent division width: var textareaWidth = document.getElementById('entry_3').scrollWidth;document.getElementById('parent').style.width = textareaWidth + 'px'; But anyhow the above approach doesn't seem to work in Chrome/Safari:Demo: http://jsfiddle.net/RainLover/snTaP/ Open the above demo in Chrome/Safari >> insert some text into the textarea >> highlight/select a line and drag your mouse to the right and you'll see the scrollbar. Or use the keyboard keys Page Up and Page Down. Any corrections or other solutions?
  10. I tried id, but it didn't work: var iframe = document.getElementById('target'); function displayResult() { if (textarea.value) { iframe.open(); iframe.write(textarea.value); iframe.close(); } window.setTimeout(displayResult, 10); } I also updated my question for clarification.
  11. I wonder why the following sample code doesn't work properly: <!DOCTYPE html><html> <head> <title></title> <style type="text/css"> textarea, iframe { display:block; width:300px; height:100px; margin:3px; padding:3px; border:1px solid #CCC; } </style> </head> <body> <textarea id="field" onfocus="getFocus();" onblur="loseFocus();">This is some text.</textarea> <iframe name="target"></iframe> <script> var textarea = document.getElementById('field'); var iframe = window.target.document; function displayResult() { if (textarea.value) { iframe.open(); iframe.write(textarea.value); iframe.close(); } window.setTimeout(displayResult, 10); } function getFocus() { if (textarea.value == textarea.defaultValue) { textarea.value = ''; } } function loseFocus() { if (textarea.value == '') { textarea.value = textarea.defaultValue; } } displayResult(); </script> </body> </html> Demo: http://jsfiddle.net/RainLover/4ksMR/ The iframe content is supposed to get updated in real time -- as soon as the textarea content changes by keyboard or mouse. This approach is an alternative to the oninput event. But since oninput isn't well-supported across different browsers I decided to create a timer to compare the current text field value with its value in 10 milliseconds before.
  12. Thanks for the answer! Do you know how I can display the focused field error?
  13. Objective: I'd like to display the focused field error message in a container. What I've done so far: <!DOCTYPE html><html><head><title></title><style type="text/css">label {display:inline-block; width:60px;}</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script><script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"></script><script type="text/javascript">$(document).ready(function(){$("form").validate({messages: { name: "Please specify your name.", email: { required: "We need your email address to contact you.", email: "Your email address must be in the format of name@domain.com." }, url: "A valid URL, please.", comment: "Please enter your comment." },showErrors: function(errorMap, errorList) { if(errorList.length) { $("span").html(errorList[0].message); } }});});</script></head><body><span></span><form action="#"><div><label for="entry_0">Name *</label><input type="text" class="required" name="name" id="entry_0"></div><div><label for="entry_1">Email *</label><input type="text" class="required email" name="email" id="entry_1"></div><div><label for="entry_2">URL</label><input type="text" class="url" name="url" id="entry_2"></div><div><textarea class="required" name="comment" rows="7" cols="35"></textarea></div><div><input type="submit" name="submit" value="Submit"></div></form></body></html> Demo: http://dl.dropbox.co...ample-form.html Problems: If you click the submit button, the container(span) shows the first error message, no matter which field was focused. Focusing on fields using the Tab key works well (except on the URL field), but focusing with a mouse doesn't update the span HTML correctly.
  14. Thanks for the answer, but I still don't understand the difference between the first and second example although I read your explanation a few times.
  15. In the second example the parent width is smaller than the child total width and the scrollbars should appear.
  • Create New...