Robert Ingmarsson

Ranch Hand
+ Follow
since Jan 12, 2015
Robert likes ...
Netbeans IDE PHP Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robert Ingmarsson

Best ranchers!

I am working on a simple datepicker using pure javascript and DOM. I have encountered a weird
problem in the process that updates the calendar through an on click event handler.  This event
handler is registered to my previous and next date buttons.

The first function is called clearList("cal-days");, the second updateLabel();
and the third is called updateCalendar();

This is what the function clearList(id) looks like

I am using a ul list as a component for displaying week days and dates. Everything is working fine until when it comes to
the update and add date function - updateCalendar(); The list date items won't clear from the previous or next month selection.
Am I doing this right? I am appending new list items in a for loop like the small code below shows.  

My date list or mainList as I call it won't remove the items from the previous selection instead it keeps them
so they are increasing all the time. What am I missing here? Can anyone see the solution to my problem here?
Sorry for the small amount of code that I posted here. I have a very large script file at my hands but I decided to pick
that part of code which is troubling me to display here in this post. I hope someone knows the
correct procedure here and can help me move on.

Very best regards,




I must have solved this now. I created a function called getDaysUntilMonday() and it returns 2
(Saturday, Sunday as of this day, Friday)

Well that was me in a nutshell. Thanks a lot for the hints it helped!  


Best ranchers!

Thank you so much for the answer. But I am completely stuck with this. I am still struggling date handling in javascript.
Could anyone show how it's done when it comes to calculating how many days to a specific day in the week
in my case it is monday from the current day? I  think one must use percentage in the calculation here but i am not
sure. Sorry for being a slow learner.

Im terrible at all things math and still i code every day    

Best Wishes,
Hello, ranchers!

I have begun work on a simple calendar in javascript. I have studied some date handling in javascript but im still very new to that math. My issue here is that I need to come up with a function that calculates how many days there are left until monday from the current day in the week.  

I know this must sound very simple to many of you but I wan't to see how the pros do it. So if anyone would like to pinch me in the right direction I would be very

I know how to get the current year, month and day / date of a date object. But my math limitations are the big bandit here.

Ok, that's it from me so far!
Thanks for reading!

Best ranchers!

I have a question about event handling in javascript. I need to figure out a crossbrowser friendly way to keep track
on the mouse when the user leaves a certain div element.

I know about the "mouseleave" attribute in the addEventListener method, but it is not ie compatible and thats the
eye of the problem. I have tested around with the event.cancelBubble  = true (ie) and event.stopPropagation (w3c)

How can I prevent - in ie - a div from closing after the mouse leaves a li-element in a list and when the mouse leaves
the parent element in this case the former mentioned div tag?

Thanks for visiting!

Best ranchers!

Thanks for all the replies here.

I am just wondering what is the procedure to detect if a mouse pointer is outside
a specific element such as a div tag?

I am looking into pageX and pageY methods on google is that the correct approach?
I wan't to be able to capture events when the mouse leaves my menu element.
Is it possible to accomplish that?

Best regards,
Mr. Bibeault!

Do you mean replacing and removing elements using dom?

I am completely stuck here. My script will still only run one time per page load.
It's almost fascinating to watch   It won't execute the method in the function call
in the loop more than once.

You mentioned something earlier about replacing the class names? I am using ids
to find the divs. I know about getElementsByClassName.

Has anyone encountered this phenomena before please give a comment or two.


Best, Mr. Bibeault!

Sorry for a late reply. The problem still occur. The script still only executes after a page load. I will definately consider using another approach
with the addEventListener method.

By the way, with "destroyed", are you refering to the method clearTimeout, i just realized I missed it out? What was your thoughts to this?

Today I will look into an alternate approach.

Best regards,
Best, racnhers!

I am developing a script for a dropdown menu component in pure javascript and dom.
The html markup is printed from a php function. My problem is with the javascript part.
The menubar has a "My Profile" menu which has a submenu that consists of several items.

When I click on the "My Profile" menu then its submenu should appear repeatedly times
when the user hover over it with the mouse which is the general way. But as it is now, this
event gets triggered only once per page load and I can't understand why?

Below is the code for my drop down component it is hardly commented but I hope that a viewer
still will get a clear idea of what is going on. If the html markup is required as necessary material
then I will post the php code that generates it. But for now here is my javascript code.

Please forgive for maybe a badly described issue. I am a little bit stressed out over this.
Thank you very much in advance!

Best regards,

Best, all!

First of all I must say that this problem that I have encountered is of a very complex nature to me. I am terrible at explaining my problems here in english so have patience with me. Also forgive me if I don't have any code at the moment to post here to demonstrate the problem from that point of view. I have mainly only questions. And I am not
sure on my reasoning or logic.

With that said I have a project in which I have a JTree that is populated with parent nodes that has user objects which can contain user defined information about stores of different kind, like their respective type of branch, number of employees and their financial income per year and so on. The user inserts theese with the click of a button in a form in a JDialog. The information in the store info nodes are displayed in that fore mentioned form. The user can also insert child nodes to theese Store nodes and they are called Department nodes. So I have a JTree that consists of Store and Department - nodes.

I know how to traverse or loop though a JTree, insert and remove nodes from the model and I always reload the model after each such action. My problem is how to code a counter that let the user know at which store info node he or she is at. This counter should increment for every new store info node the user adds to the model and for every deletion of a store info node the counter should move back up.

Example of JTree - structure ( during insert - mode )
Store Info

  Store 1
      Department 1
      Department 2

  Store 2
      Department 1
      Department 2
      Department 3

  Store 3
      Department 1
      Department 2


The user edits the names of the stores and departments in the form that is presented to him or her in add mode. My problem like my question is that I don't know how to write the counter that must be displayed in each Store node after the user have added one to the model of the JTree.  If the user deletes Store 2 then I want the counter to remember that node 2 was deleted were three Store nodes in the JTree so it starts to count from 3 when the next Store node is inserted by the user. Can a helpful soul here push me in the right direction. I am completely stuck and time limited. I hope I have not been to complicated thoughout theese lines.

I should mention that I am looking in to the TreeModelListener interface and is experimenting around with the treeNodesInserted -and treeNodesRemoved - methods, would that be in the right direction?.

Many thanks for your visit, Sir!
Kindly, Robert!
9 months ago
@Tim Holloway!

I tried your regex but it gave me an error exception as listed below

Best regards,
9 months ago
@Carey Brown

I have written an example of what I am trying to accomplish. This is just a loose sample and has nothing to do with the application I am working on at the moment. But it gives an idea of what kind of a problem that I have encountered.

I hope that helps to see what's bothering me. My english is like my java, like everything else in my life, nothing is real, all is purely on a wannabe level  

Kind Regards,


9 months ago
Hi, again!

I think I have found a solution to my problem here.

Some what hasty maybe. But I would have liked a single regex string for this situation. Sorry for my bad code.

Thanks for your visit,

9 months ago
Best all!

For example I have tried the code

But the code and regex sample i have supplied here above only tests if a strings starts with a whitespace character or not. I wan't to check
if a string does not starts with a whitespace and only contains numbers. Sorry if I am confusing anyone. Not my intention. Thanks for
your patience with me.

9 months ago
@Stephan Van Hulst

Valid strings in this situation would be


Invalid strings would be like this

" 1"
"   2"
" 2dsds"

I haven't tried that much regex for this case, I am still only at a research level.
There is the non-regex methods "startsWith", "contains", "Character.isDigit" and so on that I have experimented with
but I believe regex is best suited here. Thanks for your reply!

9 months ago