473,382 Members | 1,420 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,382 software developers and data experts.

pulling a var from a js file

Hi,
I am not doing too well here.

In the head I have:
<link type="text/css" rel="stylesheet" href="myfirst.css">
<script src="myfirst.js" type="text/javascript"></script>

I have the following in 'myfirst.js' file:
var writastring ="<table width="250" border="2"><tr>
<td>Here is my first script text</td></tr></table>"

I have the following in the myfirst.css:
#ontheleft{position:absolute; left:10px; top:50px; }

In the body of the HTML file directly below the body tag is this:
<div id="ontheleft">
<script language="javascript">
document.write(writastring)
</script>
</div>

My problem is that it writes.......Fanfare........
exactly nothing.. nada.

And yes they are all in the same path.
Even if I change to this: var writastring="OK! Write this"
nothing is written. Even leaving out the Div tags nothing
changes.

The purpose of this exercise is to assemble content in the
JS file and then write it in any number of pages.

What have I done wrong? Any help would really be appreciated.
f.
Jul 23 '05 #1
6 1348
> var writastring ="<table width="250" border="2"><tr>
<td>Here is my first script text</td></tr></table>"


Try

var writastring ="<table width=\"250\" border=\"2\"><tr>

<td>Here is my first script text</td></tr></table>"

Maybe it would help.

Jan
Jul 23 '05 #2
Jan Ebbe Jensen wrote:
var writastring ="<table width="250" border="2"><tr>
<td>Here is my first script text</td></tr></table>"


Try

var writastring ="<table width=\"250\" border=\"2\"><tr>

<td>Here is my first script text</td></tr></table>"

Maybe it would help.

Jan

I changed it as you suggested and can't believe I made the bonehead
error of having multiple quote marks!
I changed it to this in the js file:

var writastring ="<table width='250' border='2'><tr><td>Here is my first
script text</td></tr></table>"

Unfortunately it doesn't run. Now then, if I define this variable
in the html file (either in the head or body) and then run it,
it works fine. The problem is when the content is defined in the
js file. As I said before, the idea is to assemble the content for
this particular division somewhere where I can have one copy of it
and then paste it into each page as it loads, making it easy to
change for the entire site.
I must be doing something very basic - wrong.
Thanks for the help!

f.
Jul 23 '05 #3
It should work. It works fine at my computer. Try this code:

test.html - file

<html>
<head>
<link type="text/css" rel="stylesheet" href="myfirst.css">
<script type="text/javascript" src="myfirst.js"></script>
</head>
<body>
<div id="ontheleft">
<script language="javascript">
document.write(writastring);
</script>
</div>
</body>
</head>

myfirst.js - file

var writastring ="<table width=\"250\" border=\"2\"><tr><td>Here is my first
script text</td></tr></table>";

myfirst.css - file

#ontheleft {
position:absolute; left:10px; top:50px;
}

Save the files in the same directory.

Jan
Jul 23 '05 #4
Jan Ebbe Jensen wrote:
It should work. It works fine at my computer. Try this code:

test.html - file

<html>
<head>
<link type="text/css" rel="stylesheet" href="myfirst.css">
<script type="text/javascript" src="myfirst.js"></script>
</head>
<body>
<div id="ontheleft">
<script language="javascript">
document.write(writastring);
</script>
</div>
</body>
</head>

myfirst.js - file

var writastring ="<table width=\"250\" border=\"2\"><tr><td>Here is my first
script text</td></tr></table>";

myfirst.css - file

#ontheleft {
position:absolute; left:10px; top:50px;
}

Save the files in the same directory.

Jan

Thanks Jan! Once I used the proper escape on the string variable
and then found several cr/lf that made the code unreadable, all
is well. I couldn't have done it without the help.

Thank you
Thank you

f.
Jul 23 '05 #5
fritz wrote:
[...]
Unfortunately it doesn't run. Now then, if I define this variable
in the html file (either in the head or body) and then run it,
it works fine. The problem is when the content is defined in the
js file. As I said before, the idea is to assemble the content for
this particular division somewhere where I can have one copy of it
and then paste it into each page as it loads, making it easy to
change for the entire site.


Remember that anyone with JavaScript disabled or a non-JavaScript
browser will not see your dynamic content.

The type of script that you are suggesting is often run at the server
to ensure that what is sent to the user is HTML and has no
client-side dependencies outside support for stated the DOCTYPE.

[...]

--
Fred
Jul 23 '05 #6
Fred Oz wrote:
Remember that anyone with JavaScript disabled or a non-JavaScript
browser will not see your dynamic content.

The type of script that you are suggesting is often run at the server
to ensure that what is sent to the user is HTML and has no
client-side dependencies outside support for stated the DOCTYPE.

[...]


Thank you Fred!

Unfortunately I have absolutely no idea how I would even start to
do what you mentioned. I am just beginning the javascript world and have
no experience with the server side at all.

I was planning to mention to visitors on the opening page that
javascript and a modern browser were neccessary.

Perhaps someday I will be able to understand what you call the
server side. I assume you mean something to do with CGI? But thanks for
the comments.

f.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel | last post by:
what is the best way to quickly make a mechanism to configure a windows service at runtime? external app that remotes in, custom commands, pulling mechanism to config file?
0
by: acool | last post by:
I pretty much have the code for dropping into a SQL DB I also have the code for pulling a file using an ASPX page but I am a little fuzzy on the methodology of how the complete process would work....
4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
1
by: Usarian Skiff | last post by:
I'm pulling a list of data from an excel file. When I open Excel files directly, if someone else has it open, I can select 'READ-ONLY' from a pop-up. When accessing the file from within my...
2
by: elyob | last post by:
Hi, I'm looking at pulling a string from a source file and am wondering the best way to do this. I have a starter and ender quote but am just wondering the best way to do this? Regular expressions?...
5
by: akelly_image | last post by:
Okay, if anyone could toss me some idea's here, please bare with my noobish questions, I just picked up VB2005 Pro about a week ago. ( no prior VB at all ) Here's my issue.. I'm pulling...
27
by: affiliateian | last post by:
Is there a simple piece of php code(s) that can pull the title of a web page out? We need to pull the words in between <title></titleand insert it into stumble upon. Here is what their requirements...
4
by: hall.jeff | last post by:
There's a government website which shows public data for banks. We'd like to pull the data down programmatically but the data is "hidden" behind .aspx... Is there anyway in Python to hook in...
3
by: Donkeyoz | last post by:
Hi all, Trying to do something fairly basic but am getting caught up on it. I am trying to extract text from a .txt file into an array line by line and then dissect that line into various parts,...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.