473,770 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What am I doing wrong? js & function()

Ken
I want to write a js variable inside a function to a web page.

test.js

try_picture();
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5:& nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5" ></td></tr>';
}

HTML

This is part of a table.

<script language="javas cript"
type="text/javascript">doc ument.write(pic ture);</script>

If I remove the function command, the picture is written into the HTML. The
function is the problem.

I have tried try_picture(pic ture) and function try_picture(pic ture). It did
not work.

I would appreciate any suggestions.

I am missing something.

Ken

Jul 23 '05 #1
5 1263
Ken wrote:
try_picture();
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5:& nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5" ></td></tr>';
}


Does this do what you want?

<head>
<script type="text/javascript">
function try_picture() {
var picture = '<tr>\n<td colspan=2 align=\"right\" >\n<font size=2>';
picture += 'Picture 5: </font>\n</td>\n<td colspan=2>\n';
picture += '<input type=\"file\" size=68
name=\"picture5 \">\n</td>\n</tr>';
document.write( picture);
}
</script>
</head>

<body>
<form>
<input type="button" onclick="try_pi cture()" value="Try Picture">
</form>
</body>

MIke

Jul 23 '05 #2
Ken
Close, but I want to write the js script on the original html page and not a
new page.
form>
<script language="javas cript"
type="text/javascript">doc ument.write(pic ture);</script>
<input type="button" onclick="try_pi cture()" value="Try Picture">
</form>

"mscir" <ms***@access4l ess.com.net.org .uk> wrote in message
news:10******** *****@corp.supe rnews.com...
Ken wrote:
try_picture();
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5:& nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5" ></td></tr>';
}
Does this do what you want?

<head>
<script type="text/javascript">
function try_picture() {
var picture = '<tr>\n<td colspan=2 align=\"right\" >\n<font size=2>';
picture += 'Picture 5: </font>\n</td>\n<td colspan=2>\n';
picture += '<input type=\"file\" size=68
name=\"picture5 \">\n</td>\n</tr>';
document.write( picture);
}
</script>
</head>

<body>
<form>

<script language="javas cript"
type="text/javascript">doc ument.write(pic ture);</script> <input type="button" onclick="try_pi cture()" value="Try Picture">
</form>
</body>

MIke

Jul 23 '05 #3
mscir wrote:
Ken wrote:
try_picture();
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5:& nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5" ></td></tr>';
}


Sorry, I goofed, this approach might work:

<script type="text/javascript">
function showpic(targetI D) {
var picture = '<tr><td colspan=2 align=\"right\" ><font size=2>';
picture += 'Picture 5: </font></td><td colspan=2>';
picture += '<input type=\"file\" size=68 name=\"picture5 \"></td></tr>';
document.getEle mentById(target ID).innerHTML=p icture;
}
</script>
</head>

<body>
<table width=100 border=1>
<tr>
<td><div name="pic1" id="pic1"></div>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br>
<form>
<input type="button" onclick="showpi c('pic1')" value="Show Pic">
</form>
</body>

Jul 23 '05 #4
Lee
Ken said:

I want to write a js variable inside a function to a web page.

test.js

try_picture( );
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5: &nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5 "></td></tr>';
}

HTML

This is part of a table.

<script language="javas cript"
type="text/javascript">doc ument.write(pic ture);</script>

If I remove the function command, the picture is written into the HTML. The
function is the problem.


The problem is that you have declared picture to be a local
variable of try_picture(). If you want to reference it from
outside of that function, it must be a global variable.
The simplest fix is to remove the "var" keyword.

Jul 23 '05 #5
Ken wrote:
I want to write a js variable inside a function to a web page.

test.js

try_picture();
function try_picture() {
var picture = '<tr><td colspan=2 align=right><fo nt size=2>Picture
&nbsp;&nbsp;5:& nbsp;</font></td><td colspan=2><inpu t type=file size=68
name="picture5" ></td></tr>';
}

HTML

This is part of a table.

<script language="javas cript"
type="text/javascript">doc ument.write(pic ture);</script>

If I remove the function command, the picture is written into the HTML. The
function is the problem.

I have tried try_picture(pic ture) and function try_picture(pic ture). It did
not work.

I would appreciate any suggestions.

I am missing something.

Ken


function try_picture() {
// split acorss multiple lines to prevent wrapping
return '<tr><td colspan=2 align=right>' +
'<font size=2>Picture& nbsp;&nbsp;5:&n bsp;</font>' +
'</td><td colspan=2>' +
'<input type=file size=68 name="picture5" >' +
'</td></tr>';
}

<script type="text/javascript">doc ument.write(try _picture());</script>

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #6

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

Similar topics

5
1845
by: tin | last post by:
<script language="Javascript"> <!-- function apri (theURL,winName,features){ window.open (theURL,winName,features); var a=null; oldwindow = window.self; oldwindow.opener = window.self; oldwindow.close(); } -->
7
6036
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************************************** GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31) End Function If I enter dtDay value of...
2
1804
by: Phil Certain | last post by:
Hi, Relative newbie to .Net but experienced with classic ASP. I am trying to create a simple business object to contain commonly used functions. This is what I have done: 1 - Created a simple vb file containing: Imports System.Data.SqlClient Imports System.Web.HttpUtility
0
2667
by: Steve | last post by:
I have a gridview which uses an objectdatasource for its select and delete. The delete command uses the function below. The delete itself works but the extra logic which requires parameters AccountDebitID and AccountCreditID does not work. 'Delete a transaction Sub deletetrans(ByVal transactionid As Integer, ByVal transactionamount
8
2069
by: watkinsdev | last post by:
Hi, I have created a mesh class in visual studio 6.0 c++. I can create a device, render objects and can edit the objects by for instancnce selecting a cluster of vertices and processing the vertices and can do this multiple times on a sinlge vertex cluster. The problem I have been encoutering is that, if I select a second vertex cluster and try to edit that , the program crashes.
4
292
by: Robert Dufour | last post by:
I have two classes , class1 and class2 In class1 I have Public Overload function Fct1(paramlist) as string some code end function Public overloads Function Fct1(otherparamlist) as string some code
16
1915
by: SirG | last post by:
I'm looking for an explanation of why one piece of code works and another does not. I have to warn you that this is the first piece of Javascript I've ever written, so if there is a better way or a simpler answer, by all means show me the light! What I'm trying to do is refresh the page at a timed interval ( actually redirect the page... ) and I have a simple piece of code I got from the net that works, but I need to modify it a little...
1
6663
by: eastlands | last post by:
I need to use an unmanaged c++ dll which uses structs that contain callbacks and also functions. I have included the appropriate c++ definitials and my c# translations below. I first defined the parameters as c# structs, but when I tried the call (to RtcInitialize) I got the following error: MarshalDirectiveException Method's type signature is not PInvoke compatible. I then changed the structs to classes but now I get the following...
3
1638
by: burtoncn | last post by:
Hi, Just a little background information on the project I am working on! I am responsible for creating a database to automatically generate travel claims for conference attendees (Approx. 300) using Access 2003. For our staff to accurately determine which meal allowances they are entitled to claim, we have to determine the travel distance and travel time using Google Map (something similar). For example: an Attendee X has to be at...
16
3449
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName), _netguid(netguid) {}
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.