473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

To write a code inside DIV layer

12
hi all,
i have my header, where i do the following code to call a random image from the site folder:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript"> 
  2.  
  3. p=65*Math.random(); 
  4. d=parseInt(p); 
  5. document.write ("<table background='../pics/site/"+d+".jpg'></table>"); 
  6.  
  7. </script> 
but now i want to replace a table with a DIV, to make the pageload faster.

so i have tried the following:

Expand|Select|Wrap|Line Numbers
  1. document.write ("<div style="background: url('../pics/site/"+d+".jpg')"></div>") 
but this is not working.
can You please help me, how to write the correct code?
thx.
May 1 '07 #1
4 2685
Expand|Select|Wrap|Line Numbers
  1. document.write ("<div style="background: url('../pics/site/"+d+".jpg')"></div>") 
Is the above a direct copy from your script? If so the quotes around the style need to be escaped, see below.

Expand|Select|Wrap|Line Numbers
  1. document.write ("<div style=\"background: url('../pics/site/"+d+".jpg')\"></div>") 
  2.  
You may also need to explicitly set the width and height of the div in the style attribute. If still no luck, change the style property background to background-image keeping the value the same. The property background usually colour, image url and position values to be present.
May 1 '07 #2
blobb
12
no, this did not help.

document.write ("<div style=\"background-image: url('../pics/site/"+d+".jpg')\"></div>") - this is also not helping..

can You please suggest, how to write in the correct height and width? then i'll try again.
May 1 '07 #3
no, this did not help.

document.write ("<div style=\"background-image: url('../pics/site/"+d+".jpg')\"></div>") - this is also not helping..

can You please suggest, how to write in the correct height and width? then i'll try again.
Expand|Select|Wrap|Line Numbers
  1. document.write ("<div style=\"background-image:url('../pics/site/"+d+".jpg');width:npx;height:mpx;border:1px solid #000000;\"></div>")  
  2.  
Added a border to make sure the div is the expected size. If the image still isn't appearing then the page in the url may be incorrect (obviously once you're happy the image is appearing get rid of the border property). Do all the images have the same dimensions? How are more images added? Is this in a HTML page or a script?
May 1 '07 #4
blobb
12
thanx a lot!!!
May 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: silviu | last post by:
Hi All, I have to write C++ code (server code) that will compile/run on both Windwos and Linux OS's. Could someone give me some pointers to info on this matter. Thanks in advance for your...
1
by: Gareth | last post by:
Hi, I am very new to JavaScript and programming. What I am trying to do is create a layer inside a pop up but the layer must stay in the centre of the pop up. Is that possible? It would be...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
14
by: WUV999U | last post by:
Hi I am fairly familiar in C but not much. I want to know how I can write a html parser in C that only parses for the image file in the html file and display or print all the images found in...
6
by: Kobu | last post by:
Do the "larger" input functions like scanf, gets, fgets use fgetc to take input or an operating system call function like read() (I know it could be any "way", but I'm trying to find out how it's...
5
by: Jay | last post by:
Hello everyone, I just got done taking a small course in ASP.NET and I'm completely sold. This is amazing compared to original ASP. My question is about the preferred method of coding the asp...
2
by: | last post by:
Today I learned that creating cookies inside of a custom class in ASP.NET 2.0 requires that you prefix it with HttpContext.Current..., e.g. : ...
2
by: ss | last post by:
Hi, Can anybody give me a SAMPLE VALIDATION CODE (MOST COMMON ONES) IN BUSINESS LOGIC LAYER & DATA ACCESS LAYER I REPEATE SAMPLE VALIDATON CODE IN BLL & DAL BYE SS
3
by: HareshKarkar | last post by:
Hi , I'm calling some Javascript function to write value in the layer. I'm trying to achieve it by using eval() function. Please look at the code below: function showMore(tempLayerNum,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.