473,781 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems calling a function

JS
I have made a function createFirstMenu where I call "resetMenu" in a
JavaScript. But nothing happens when I call resetMenu.

function createFirstMenu (sel){
sel = document.getEle mentById('sel1' );
resetMenu(sel);
}

function resetMenu(sel){
sel.length = 0;
opt = document.create Element('OPTION ');
sel.appendChild (opt);
opt.value = "";
opt.text = "-- Choose--";
}

This is the form where I call createFirstMenu when the page loads.

<body onload="createF irstMenu('sel1' );">
<form name="sels" method="post" action="">
<select name="sel1" id="sel1" onchange="creat eSecondMenu('se l1','sel2');">
</select>

<select name="sel2" id="sel2" onchange="creat eThirdMenu('sel 1','sel2',
'sel3');">
<option value="">-- V&aelig;lg --</option>
</select>

<select name="sel3" id="sel3">
<option value="">--V&aelig;lg--</option>
</select>

<input name="search" type="text" id="search">
&nbsp;
<input type="submit" name="Submit" value="Søg">
</form>

Hope someone can help!
Jul 23 '05 #1
11 1781
JS
Again it was because I overlooked an "{". I have wasted quite some hours on
these syntax errors by now. I use Dreamweaver and for some reason this
program don't have any syntax check (like eclipse) for javascript or JSP.

Hopefully there are some better programs to write these things in, because
syntax correction are one of the most basic features that a program should
have. Any recommendations ??
Jul 23 '05 #2
JS wrote on 30 mei 2005 in comp.lang.javas cript:
function createFirstMenu (sel){
sel = document.getEle mentById('sel1' );
resetMenu(sel);
}


Not that it matters,
but why enter a parameter in the local variable

sel

--- function createFirstMenu (sel){

and then immediately changing the content to

document.getEle mentById('sel1' );

--- sel = document.getEle mentById('sel1' );

?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #3
Zif
JS wrote:
[...]
Hopefully there are some better programs to write these things in, because
syntax correction are one of the most basic features that a program should
have. Any recommendations ??


<URL:http://www.editplus.co m/>

Gets my vote.

--
Zif
Jul 23 '05 #4
JS wrote:
Again it was because I overlooked an "{". I have wasted quite some hours on
these syntax errors by now. I use Dreamweaver and for some reason this
program don't have any syntax check (like eclipse) for javascript or JSP.

Hopefully there are some better programs to write these things in, because
syntax correction are one of the most basic features that a program should
have. Any recommendations ??


Firefox's JavaScript console is very helpful for syntax errors, usually
providing a line number and giving a link to the source so you can
easily fix them.

For more serious stuff there's Mozilla's JavaScript debugger 'Venkman'

<URL:http://www.mozilla.org/projects/venkman/>

And Douglas Crockford's JavaScript verifier 'JSLint':

<URL:http://www.crockford.c om/javascript/lint.html>
Other Firefox developer tools (including extensions to the JavaScript
console, HTML, CSS and RSS tools):
<URL:https://addons.mozilla. org/extensions/showlist.php?ap plication=firef ox&category=Dev eloper%20Tools>

Have fun.

--
Rob
Jul 23 '05 #5
JS

"Evertjan." <ex************ **@interxnl.net > skrev i en meddelelse
news:Xn******** ***********@194 .109.133.242...
JS wrote on 30 mei 2005 in comp.lang.javas cript:
function createFirstMenu (sel){
sel = document.getEle mentById('sel1' );
resetMenu(sel);
}


Not that it matters,
but why enter a parameter in the local variable

sel

--- function createFirstMenu (sel){

and then immediately changing the content to

document.getEle mentById('sel1' );

--- sel = document.getEle mentById('sel1' );

?


I have this form:
<body onload="createF irstMenu('sel1' );">
<form name="sels" method="post" action="?page=j ubii">
Kategori:&nbsp; &nbsp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eSecondMenu('se l1','sel2',
'sel3');">
</select>
....
..
..
..

But for some reason I don't get access to sel1 in createFirstMenu if I don't
explicitly grap it with:

sel = document.getEle mentById('sel1' );

Guess I am missing something?
Jul 23 '05 #6
Zif
JS wrote:
"Evertjan." <ex************ **@interxnl.net > skrev i en meddelelse
news:Xn******** ***********@194 .109.133.242...
JS wrote on 30 mei 2005 in comp.lang.javas cript:

function createFirstMenu (sel){
sel = document.getEle mentById('sel1' );
resetMenu(sel);
}


Not that it matters,
but why enter a parameter in the local variable

sel

--- function createFirstMenu (sel){

and then immediately changing the content to

document.getE lementById('sel 1');

--- sel = document.getEle mentById('sel1' );

?

I have this form:
<body onload="createF irstMenu('sel1' );">
<form name="sels" method="post" action="?page=j ubii">
Kategori:&nbsp; &nbsp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eSecondMenu('se l1','sel2',
'sel3');">
</select>
...
.
.
.

But for some reason I don't get access to sel1 in createFirstMenu if I don't
explicitly grap it with:

sel = document.getEle mentById('sel1' );

Guess I am missing something?


The local variable 'sel' is created here:

function createFirstMenu (sel){

It is passed the string 'sel1' from the onload event:

<body onload="createF irstMenu('sel1' );">

The content of 'sel' is replaced with a reference to the element
with id 'sel1' using a hard-coded parameter:

sel = document.getEle mentById('sel1' );

which seems to ignore the value passed to sel in the first place. To
re-use the local variable 'sel', then:

sel = document.getEle mentById(sel);

would make more sense, but probably better would be to use the forms
collection and reduce reliance on getElementById (although it is
supported by perhaps 95% of browsers in use):

sel = document.forms['sels'].elements[sel];

or a reference to the required element could be passed directly from
the onload event:

<body onload="
createFirstMenu (document.forms['sels'].elements['sel1']);
">

Thereby removing the hard-coded values from the script. Having gone
that far, the usefulness of createFirstMenu () becomes moot, since all
it does is call resetMenu() - the onload is effectively:

<body onload="
resetMenu(docum ent.forms['sels'].elements['sel1']);
">

The resetMenu() function is:

function resetMenu(sel){
sel.length = 0;
opt = document.create Element('OPTION ');
sel.appendChild (opt);
opt.value = "";
opt.text = "-- Choose--";
}

When modifying the length of the select to change the number of
options, it seems appropriate to set it to the new length directly:

sel.length = 1;

and then modify the remaining option(s):

sel[0].value = "";
sel[0].text = "-- Choose--";

so now you have:

function resetMenu(sel){
sel.length = 1;
sel[0].value = "";
sel[0].text = "-- Choose--";
}

If there are many option attributes to modify, it may be better
(faster) to create a local variable with a reference to the option:

function resetMenu(sel){
sel.length = 1;
var s = sel[0];
s.value = "";
s.text = "-- Choose--";
//...
}


--
Zif
Jul 23 '05 #7
Zif wrote:
JS wrote:
[...]
Hopefully there are some better programs to write these things in, because
syntax correction are one of the most basic features that a program should
have. Any recommendations ??


<URL:http://www.editplus.co m/>

Gets my vote.

--
Zif


Aside from vi/vim, EditPlus is my only text editor.
Never heard anyone else mention it but it's the best I've seen.

Jul 23 '05 #8
JS
I am still confused about the way arguments are passed. In my test.jsp page
I have:
<body onload="createF irstMenu('sel1' );">
<form name="sels" method="post" action="?page=j ubii">
Kategori:&nbsp; &nbsp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eSecondMenu('se l1','sel2',
'sel3');">
</select>
&nbsp;&nbsp;&nb sp;&nbsp;Kriter ium:&nbsp;&nbsp ;
<select name="sel2" id="sel2" onchange="creat eThirdMenu('sel 1','sel2',
'sel3');">
<option value="0">-- V&aelig;lg --</option>
</select>
</form>

And in my JavaScript I have:

function createFirstMenu (sel){
sel = document.getEle mentById(argume nts[0]);

for(i=0;entry.l ength>i;i++){
opt = document.create Element('OPTION ');
sel.appendChild (opt);
opt.value = i+1;
opt.text = entry[i][0];
}
}
If I call createFirstmenu with "sel2" nothing changes:

<body onload="createF irstMenu('sel2' );">
....
....
....

For some reason it does not matter which argument I give createFirstMenu in
test.jsp. I have even tried:

<body onload="createF irstMenu('bla') ;">

and the first menu still gets vreated as it should. What am I missing?
Jul 23 '05 #9
Lee
JS said:

I am still confused about the way arguments are passed. In my test.jsp page
I have:
<body onload="createF irstMenu('sel1' );">
<form name="sels" method="post" action="?page=j ubii">
Kategori:&nbsp ;&nbsp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eSecondMenu('se l1','sel2',
'sel3');">
</select>
&nbsp;&nbsp;&n bsp;&nbsp;Krite rium:&nbsp;&nbs p;
<select name="sel2" id="sel2" onchange="creat eThirdMenu('sel 1','sel2',
'sel3');">
<option value="0">-- V&aelig;lg --</option>
</select>
</form>

And in my JavaScript I have:

function createFirstMenu (sel){
sel = document.getEle mentById(argume nts[0]);


Why do you do that? There's no need to use the arguments array
unless you don't know how many arguments you need to handle.

function createFirstMenu (selID) {
var sel = document.getEle mentById(selID) ;

should be easier to understand.

However, you could simplify it even further by passing a
reference to the Select object in the first place, so you
don't need to look it up by ID value:

onload="createF irstMenu(docume nt.sels.sel1)"

Jul 23 '05 #10

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

Similar topics

0
3580
by: Gary | last post by:
sorry for not cross-posting originally (originally posted in the components subgroup) I seem to have run into two documented bugs whose workarounds are incompatible. What I have is an OCX written in VB 6 that has a few classes in it. Many of the methods of the OCX are used by ASP, and so far have worked fine. I recently added a COM object reference to the DLL which consists of an SMTP client dll that is wrapped up in dual interface...
5
6090
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory loss even though I seem to be allocaitng everything; help would be *vastly* appreciated. What am I doing wrong here? I thought I was doing everything correctly (setting things to null, for example) but none of the memory seems to get replaced. ...
9
2048
by: robbie.carlton | last post by:
Hello! I've programmed in c a bit, but nothing very complicated. I've just come back to it after a long sojourn in the lands of functional programming and am completely stumped on a very simple function I'm trying to write. I'm writing a function that takes a string, and returns an array of strings which are the result of splitting the input on whitespace and parentheses (but the parentheses should also be included in the array as...
0
2483
by: Claire | last post by:
Hi Ive been using Mattias Sjögren's example at http://www.msjogren.net/dotnet/eng/samples/dotnet_dynpinvoke.asp to load an unmanaged 3rd party dll dynamically when my object is created. Calling the "CreateDllAssembly" function below does this. When my wrapper is disposed of, I want the dll to be unloaded from memory. See the "dispose" function below. All seems to work ok on the first instance of my wrapper class. (I only
0
1029
by: Tim Whelan via DotNetMonster.com | last post by:
Hi I am developing a web application using asp.net and c# and I am having some problems and im just wondering if anyone would be able to help me. My first problem is that I have a function that I want to be able to call on every page of my application is there some way of calling this function and where should this function be placed. My second problem is that I want to refresh the data in a datagrid once I have deleted a row. I have...
4
3537
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The objective in utilizing this new deployment method is to reduce the maintenance overhead as well as making it easier for my users to setup and run the application initially. I have VS 2002, Windows XP, Access XP(2000 format). He is my problem....
2
1923
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function The question may be silly or even meaning less but please............
2
3721
by: rfdes | last post by:
Hi- I could use some help resolving a problem. This explanation will be lengthy as I am trying to describe my problem without posting real code. I currently have a Win32 console application & a Win32 DLL which work correctly together. Both were written by another author and were compiled with MSVC++.net (compiling to Win32) From what I can tell, the __cdecl calling convention was used throughout. I have no idea if the DLL and app were...
14
3796
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain more why C++/CLI would be better to PInvoke than doing the PInvoke in C#? Because, usually in C# as you already know we use DLLImport and extern
3
2484
by: John Dann | last post by:
Trying to learn Python here, but getting tangled up with variable scope across functions, modules etc and associated problems. Can anyone advise please? Learning project is a GUI-based (wxPython) Python program that needs to access external data across a serial port. The first thing that I need the program to do when it starts up is to check that it can see the serial port, the first step of which is to check that it can import the...
0
9474
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
10076
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
9939
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...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
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
6729
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
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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

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.