This is probably a question for the more 'advanced' users of JavaScript.
How would I go about adding new lines of code to a JavaScript function?
Let's say I had this function...
function alertnames()
{
alert('Bob');
alert('Charlie');
}
... and I wanted to add ... alert('David') ... to that function.
I'm not worried about it working on any browser apart from IE5+ so if it doesn't work on NS no problem.
I'm sure the new Microsoft DOM for IE5+ allows you to do this and I've been going through the Microsoft website but haven't found anything yet.
Any help on this would be really cool.
Thanks.
Dynamic Functions
Moderator: General Moderators
- Fredix
- Forum Contributor
- Posts: 101
- Joined: Fri Jul 18, 2003 2:16 pm
- Location: Wehr (Eifel) Germany
- Contact:
Sorry that I can't give no answer to the question: how to edit a JS file but I noticed something diffrent:
you normally would use
to give the alert message
and have something like this in the HTML code:
you normally would use
Code: Select all
function names(name)
{
alert(name)
}and have something like this in the HTML code:
Code: Select all
<input type="button" name="noname" value"my name is..." onclick="names(Bob)" />
<input type="button" name="noname" value"my name is..." onclick="names(Charlie)" />
<input type="button" name="noname" value"my name is..." onclick="names(David)" />Yeah the example I gave above was just something to show you what I was rambing on about
The actual script I'm working on is a lot more complicated that alert()ing names 
I think I have found a way of doing it though, it's not the nicest looking code in the world but it seems to work ok.
Basically what I am doing now is storing lines of code in an array and then push()ing and pop()ing lines of code to the array... and using a stand loop to eval() each line of code.
Here's a quick example.
..seems to do the trick. It's obviously not what I was after but we gotta so what we gotta do.
I think I have found a way of doing it though, it's not the nicest looking code in the world but it seems to work ok.
Basically what I am doing now is storing lines of code in an array and then push()ing and pop()ing lines of code to the array... and using a stand loop to eval() each line of code.
Here's a quick example.
Code: Select all
var CODE = new Array('Alert("Bob")','Alert(X*13.1)');
function runCODE()
{
for(var i=0; i<CODE.length; i++)
{
eval(CODEїi]);
}
}
runCODE();