Jump to content

A couple of problems

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
17 replies to this topic

#1
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
Ok, so I have a couple of questions/problems:

1. I'm using the following script to change the 1st picture to the 2nd while the moues is on the 1st one and change back to the 1st one when its off the 2nd one.(its just for a div!)
pretty easy, I think i complicated my explanation...
mouse off - picture 1.
mouse on - picture 2.
mouse off - picture 1.

<script>


<!--


if (document.images)

	{check = true;}

	else

	{check = false;}


if (check == true){


image23= new Image();

image23.src = (image, cant post it);

image23over = new Image();

image23over.src = (image, cant post it);

// There were more images, but I couldn't post them, so I deleted

// them and left this one as an example.

}


function over(name)  {

        if (check == true){	document[name].src = eval(name + "over.src");	}}


function off(name)  {

        if (check == true){	document[name].src = eval(name + ".src");}}



//-->

</script>

And I call it like that: (in the body)
<(link, cant post it...) onmouseout="off('image23')" onmouseover="over('image23')">

<img name="image23" src="1off.jpg" border="0"></a>

// There were more images, but I couldn't post them, so I deleted

// them and left this one as an example.

Its important to remember that those are inside a div, so I gota use that compliacted script to do that simple thing.
Now, the problem:
When I load the page, all of the imges are [X]s and when I put my mouse over them, they become fine. But, I want the pictures to be like they are supposed to be from the beggining.

Any suggestions?

2. I have a clock in my site. I managed to call it only by using a form tag. I dont really care if I call it with a form tag though. But, I do care that the numbers, and characters would be centered, in a white font in the form and the form border, and background would be black. Now, I dont really know if a form tag can be manipulated to do that, so if it can't, does any one have any idea of calling the clock function in a method that would center and display in a white font the numbers and characters where i want them to be, and display them on a black background?
The clock script is:
<!-- Hide the script from old browsers --


	var timerID = null;


	var timerRunning = false;


	var id,pause=0,position=0;




	function stopclock (){


			if(timerRunning)


					clearTimeout(timerID);


			timerRunning = false;


	}




	function showtime () {


			var now = new Date();


			var hours = now.getHours();


			var minutes = now.getMinutes();


			var seconds = now.getSeconds()


			var timeValue = "" + ((hours >12) ? hours -12 :hours)


			timeValue += ((minutes < 10) ? ":0" : ":") + minutes


			timeValue += ((seconds < 10) ? ":0" : ":") + seconds


			timeValue += (hours >= 12) ? " P.M." : " A.M."


			document.clock.face.value = timeValue;


			timerID = setTimeout("showtime()",1000);


			timerRunning = true;

	}


	function startclock () {


			stopclock();


			showtime();


	}


	// --End Hiding Here -->

</script>
And I call it like that:
<BODY onload="startclock()">

	<form name="clock" onSubmit="0">

	<input type="text" name="face" size="23" value="">

             </form>
Thanks in advanced.

Edited by Mers, 18 June 2009 - 02:43 PM.
Some mispellings


#2
NatalieM

NatalieM

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts
1. I'm not sure I understand your problem but is "1off.jpg" actually an image you have stored on your server? This is the one that should appear when you load the page, before any mouse event can get fired.

#3
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
haha solved my problem man! thanks. Any ideas about the second one?

#4
NatalieM

NatalieM

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts

Mers said:

haha solved my problem man!

Glad I could help :) I know there is a majority of men on here but check again my username ;)

As for your second problem, I don't think you can use the textAlign property on an input field so you couldn't center the text in an input form. I'm actually rather puzzled as to why you are using an input field to show the clock, it doesn't seem fit for purpose.

You could display the clock in a div block element, which you could style as you want it with document.getElementById("myDiv").style.color/textAlign/backgroundColor and you could call it by a mouseover() event over the div element for example, or call it with an onload() event on the body.

#5
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
How exactly do I do that? I'm not really a pro in javascript...

#6
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
Well, I found a code somewhere... With a java applet lol... But, it works so who cares?

#7
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
java applet is different and the user needs to have the java runtime files installed, not like javascript.. so it will not work for those who do not have java installed

#8
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
Most of the people have a java ruintime files installed... I mean, you know java is very popular so most of the computers in the world have it, right?
Do you have any idea with javascript?

#9
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
To format the clock did you try CSS?

#10
Mers

Mers

    Newbie

  • Members
  • PipPip
  • 11 posts
Hmmm, I thought about it, but I dont think form tags can be manipulated like that... That's also what NatalieM said.

#11
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Applying CSS to forms

might help.

#12
NatalieM

NatalieM

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts
As I said before, you can apply CSS to forms but not the "text-align" property and as you said you wanted the text to be centered, this is going to be a problem. There is also no reason to use a form in this example anyway, let alone an input field.

Call your function the same way as you are presently doing (via body onload).

In the functions itself, you want to remove this line document.clock.face.value = timeValue; and replace it with

var myDiv = document.getElementById("myId");

myDiv.innerHTML = timeValue;

myDiv.style.backgroundColor = "black";

myDiv.style.textAlign = "center";

and you might also want to add further styling, such as padding around the text and so on.

And in your HTML page, replace your form with:

<div id="myDiv"></div>