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

delimiting parameters in a function call

Claus Mygind
571 512MB
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"

Expand|Select|Wrap|Line Numbers
  1. 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']+'\");">';
  2.  
The above code does not render the right format. This is the result of what I get.

Expand|Select|Wrap|Line Numbers
  1. <input type="button" );="" clas0011king_s01="" ,="" contactkey="" contact="" onclick="GetMoreRecs(" value="&lt;&lt; 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.
Apr 14 '11 #1

✓ answered by Claus Mygind

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:

Expand|Select|Wrap|Line Numbers
  1. td.innerHTML  =    ' Browse From&nbsp;<font color="red">'+ p['wkStart'] +'</font> to <font color="red">'+ p['wkEnd'] +'</font><br>';
  2. td.innerHTML +=    '<input class="MenuButtonText" type="button" id="pbPrev" value="<< Prev" style="visibility:'+(( p['cBof'] ) ? 'hidden': 'visible')+'">';
  3. td.innerHTML +=    '<input class="MenuButtonText" type="button" id="pbNext" value="Next >>" style="visibility:'+(( p['cEof'] ) ? 'hidden': 'visible')+'">';
  4.  
  5. var pbutton = document.getElementById("pbPrev");
  6. if (pbutton.addEventListener)
  7. {        
  8. pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue1'])},false);
  9. }
  10.  
  11. var pbutton = document.getElementById("pbNext");
  12. if (pbutton.addEventListener)
  13. {
  14. pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue2']  )},false);
  15. }
  16.  

5 1541
Dormilich
8,658 Expert Mod 8TB
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.
Apr 14 '11 #2
Claus Mygind
571 512MB
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)?
Apr 15 '11 #3
Claus Mygind
571 512MB
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:

Expand|Select|Wrap|Line Numbers
  1. td.innerHTML  =    ' Browse From&nbsp;<font color="red">'+ p['wkStart'] +'</font> to <font color="red">'+ p['wkEnd'] +'</font><br>';
  2. td.innerHTML +=    '<input class="MenuButtonText" type="button" id="pbPrev" value="<< Prev" style="visibility:'+(( p['cBof'] ) ? 'hidden': 'visible')+'">';
  3. td.innerHTML +=    '<input class="MenuButtonText" type="button" id="pbNext" value="Next >>" style="visibility:'+(( p['cEof'] ) ? 'hidden': 'visible')+'">';
  4.  
  5. var pbutton = document.getElementById("pbPrev");
  6. if (pbutton.addEventListener)
  7. {        
  8. pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue1'])},false);
  9. }
  10.  
  11. var pbutton = document.getElementById("pbNext");
  12. if (pbutton.addEventListener)
  13. {
  14. pbutton.addEventListener("click",function(){GetMoreRecs(p['TableName'], p['Key'], p['searchValue2']  )},false);
  15. }
  16.  
Apr 15 '11 #4
Dormilich
8,658 Expert Mod 8TB
Ok, an example using the DOM to create a button:
Expand|Select|Wrap|Line Numbers
  1. var b = document.createElement("button");
  2. b.type = "button";
  3. b.name = "Next";
  4. b.textContent = "Next >>";
  5. // CSS shouldn’t be inline either
  6. b.className = "MenuButtonText otherStyleClass";
  7. // execute doSomething() on click
  8. b.addEventListener("click", doSomething, false);
  9. parent.appendChild(b);
Apr 15 '11 #5
Dormilich
8,658 Expert Mod 8TB
instead of GetMoreRecs(p['TableName'], p['Key'], p['searchValue1']) you can also write
Expand|Select|Wrap|Line Numbers
  1. GetMoreRecs(p.TableName, p.Key, p.searchValue1)
Apr 15 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
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
13
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?
11
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...
2
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...
4
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...
7
by: Laurent Pointal | last post by:
on win32] Given the following: 45 .... (<generator object at 0x00A79788>,) .... File "<stdin>", line 1 SyntaxError: invalid syntax
5
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...
34
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...
9
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
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
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...
0
Oralloy
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,...
0
jinu1996
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...

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.