I want to create a function call "GetMoreRecs()" on the fly and insert 3 variables as parameters. The values of the variables are stored in an array "p" -
td.innerHTML += '<input type="button" style="visibility:'+(( p['cEof'] ) ? 'hidden': 'visible')+'" class="MenuButtonText" name="Next" value="Next >>" onClick="GetMoreRecs(\"'+p['TableName']+'\", \"'+p['Key']+'\", \"'+p['searchValue']+'\");">';
-
The above code does not render the right format. This is the result of what I get. - <input type="button" );="" clas0011king_s01="" ,="" contactkey="" contact="" onclick="GetMoreRecs(" value="<< Prev" name="Prev" class="MenuButtonText" style="visibility: visible;">
I think I am escaping the double quotes like this \"
but as you can see the result is not correct. This is for fireFox only. not interested in any other browser.
Ok I got it to work, but I am not sure if this is the cleanest way to write this code.
First I add the buttons dynamically, then I reference the buttons I just added and bind the eventListner to each button: -
td.innerHTML = ' Browse From <font color="red">'+ p['wkStart'] +'</font> to <font color="red">'+ p['wkEnd'] +'</font><br>';
-
td.innerHTML += '<input class="MenuButtonText" type="button" id="pbPrev" value="<< Prev" style="visibility:'+(( p['cBof'] ) ? 'hidden': 'visible')+'">';
-
td.innerHTML += '<input class="MenuButtonText" type="button" id="pbNext" value="Next >>" style="visibility:'+(( p['cEof'] ) ? 'hidden': 'visible')+'">';
-
-
var pbutton = document.getElementById("pbPrev");
-
if (pbutton.addEventListener)
-
{
-
pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue1'])},false);
-
}
-
-
var pbutton = document.getElementById("pbNext");
-
if (pbutton.addEventListener)
-
{
-
pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue2'] )},false);
-
}
-
5 1541
if you ask me, don’t do it with inline JavaScript. rather go for event handlers or event listeners.
those two codes don’t seem related, there are attributes in the second that are not present in the first.
besides that, there are no associative arrays in JS, use standard objects for that.
Ok I see what you are saying. Can you create an event listener example for me that is attached to the button I am creating on the fly?
Basically I am using the button's event handler "onclick". But what you are saying is I need to create an object that has the same function within it, then I have to attach that object to the button, I am creating on the fly. (like I said, I get it, but I don't see how I write that code)?
Ok I got it to work, but I am not sure if this is the cleanest way to write this code.
First I add the buttons dynamically, then I reference the buttons I just added and bind the eventListner to each button: -
td.innerHTML = ' Browse From <font color="red">'+ p['wkStart'] +'</font> to <font color="red">'+ p['wkEnd'] +'</font><br>';
-
td.innerHTML += '<input class="MenuButtonText" type="button" id="pbPrev" value="<< Prev" style="visibility:'+(( p['cBof'] ) ? 'hidden': 'visible')+'">';
-
td.innerHTML += '<input class="MenuButtonText" type="button" id="pbNext" value="Next >>" style="visibility:'+(( p['cEof'] ) ? 'hidden': 'visible')+'">';
-
-
var pbutton = document.getElementById("pbPrev");
-
if (pbutton.addEventListener)
-
{
-
pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue1'])},false);
-
}
-
-
var pbutton = document.getElementById("pbNext");
-
if (pbutton.addEventListener)
-
{
-
pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue2'] )},false);
-
}
-
Ok, an example using the DOM to create a button: - var b = document.createElement("button");
-
b.type = "button";
-
b.name = "Next";
-
b.textContent = "Next >>";
-
// CSS shouldn’t be inline either
-
b.className = "MenuButtonText otherStyleClass";
-
// execute doSomething() on click
-
b.addEventListener("click", doSomething, false);
-
parent.appendChild(b);
instead of GetMoreRecs(p['TableName'], p['Key'], p['searchValue1']) you can also write - GetMoreRecs(p.TableName, p.Key, p.searchValue1)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ashok.anbalan |
last post by:
Hi,
Can someone tell me if the language imposes any restrictions on the
maximum number of arguments that can be passed via a function call?
Thanks,
Ashok
|
by: mitchellpal |
last post by:
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?
|
by: Yelena Varshal via AccessMonster.com |
last post by:
Hello,
I have a problem with one of msaccess.exe API calls that work on my desctop
but does not work on the laptop from within MS ACCESS. There is a lot of
differences between 2 computers...
|
by: perdubug |
last post by:
Somebody told me that Tasking C166 C++ compiler has problems with
temporary objects in function call parameters. He gave me below
examples:
Case 1:Wrong:
rc = foo(&bar());
Case 2:Right:
bar...
|
by: golubovsky |
last post by:
Hi,
Is there an easy way to construct a function call out of a function and
an array of actual arguments?
e. g. given a function `fun' and an array
I need to obtain equivalent of...
|
by: Laurent Pointal |
last post by:
on win32]
Given the following:
45
....
(<generator object at 0x00A79788>,)
....
File "<stdin>", line 1
SyntaxError: invalid syntax
|
by: kris |
last post by:
Hi I have written a program which prints the hostid on a linux system.
The programm uses gethostid() function call which is defined in the
library file unistd.h. But my programm gets compiled...
|
by: Srinu |
last post by:
Hi all,
Can we assign return value of a function to a global variable? As we
know, main() will be the first function to be executed. but if the
above is true, then we have a function call before...
|
by: Yannick |
last post by:
Hi everyone -
I am not quite sure to understand what is really going on when a
function defined in one translation unit calls a function defined in a
different translation unit without knowing...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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
|
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: 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,...
|
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...
| |