473,563 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing a variable with onClick

139 New Member
HI,

How can I change a form variable with onClick?

I have a table which shows the results of a ColdFusion query. I need to have a drop down list box showing the other queries that could be sprayed into the table and want to change the variable storing the query to achieve this.

Any ideas would be appreciated!

thanks
Neil
Jul 20 '09 #1
6 5182
Dormilich
8,658 Recognized Expert Moderator Expert
basicly
Expand|Select|Wrap|Line Numbers
  1. var sql = select.value;
where select is your drop down box. (if I understand you right)
Jul 20 '09 #2
juanmendes
4 New Member
Does the drop down contain the actual SQL? That sounds injection prone. It doesn't have to be if you're careful, make sure you're not using the sql from the client directly. The drop down should contain ids that reference the queries that are hard coded on the server
Jul 20 '09 #3
ndeeley
139 New Member
hi both,

Thanks for your help. What I have actually done is generated all my tables then just hidden then with some .css, using a javascript function to show the relevant table when the link is used:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. //here you place the ids of every element you want.
  3. var ids=new Array('s1','s2','s3','s4','s5','s6','c1','c2','c3','c4','c5','c6');
  4.  
  5. function switchid(id){    
  6.     hideallids();
  7.     showdiv(id);
  8. }
  9.  
  10. function hideallids(){
  11.     //loop through the array and hide each element by id
  12.     for (var i=0;i<ids.length;i++){
  13.         hidediv(ids[i]);
  14.     }          
  15. }
  16.  
  17. function hidediv(id) {
  18.     //safe function to hide an element with a specified id
  19.     if (document.getElementById) { // DOM3 = IE5, NS6
  20.         document.getElementById(id).style.display = 'none';
  21.     }
  22.     else {
  23.         if (document.layers) { // Netscape 4
  24.             document.id.display = 'none';
  25.         }
  26.         else { // IE 4
  27.             document.all.id.style.display = 'none';
  28.         }
  29.     }
  30. }
  31.  
  32. function showdiv(id) {
  33.     //safe function to show an element with a specified id
  34.  
  35.     if (document.getElementById) { // DOM3 = IE5, NS6
  36.         document.getElementById(id).style.display = 'block';
  37.     }
  38.     else {
  39.         if (document.layers) { // Netscape 4
  40.             document.id.display = 'block';
  41.         }
  42.         else { // IE 4
  43.             document.all.id.style.display = 'block';
  44.         }
  45.     }
  46. }
  47. </script>

Thanks
Neil
Jul 21 '09 #4
juanmendes
4 New Member
Looks like a good solution, but your js code is sooooo 1995. do you really need to support browsers that don't support getElementById?

Also, your script tag shouldn't contain a language attribute, it should be

<script type="text/javascript">
Jul 21 '09 #5
acoder
16,027 Recognized Expert Moderator MVP
Correct. Change hidediv and showdiv to the following:
Expand|Select|Wrap|Line Numbers
  1. function hidediv(id) {
  2.     document.getElementById(id).style.display = 'none';
  3. }
  4.  
  5. function showdiv(id) {
  6.     document.getElementById(id).style.display = 'block';
  7. }
Jul 22 '09 #6
ndeeley
139 New Member
Thanks - i have changed it and it works fine!
Jul 22 '09 #7

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

Similar topics

6
2734
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid = server.createobject("scriptlet.typelib").guid guid=Left(guid,instr(guid,"}")) genguid=guid
2
2860
by: wjbell | last post by:
I have a piece of javascript I need to modify. Right now it changes a stylesheet in the document between style.css and no_indent.css. These are in the head of my document: <link rel=stylesheet href=/style.css> <link rel=stylesheet href=/no_indent.css> <link rel=stylesheet href=/style.css> What the code below does is toggle between...
14
2481
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only. For example, here is the main page: <html> <head> <script type="text/javascript">
2
1348
by: Ian F | last post by:
I have some javascript which allows a header, iframe and picture to be changed when the user clicks a next/previous button. In Opera, if you click next enough times to loop back to the start, or back to get to the previous one the the javascript fails. I have narrowed the problem down to Opera trying to load things from cache as it only...
1
3377
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with ***********************, I've included all the code incase that isn't where the problem is. Any help would be hugely appreciated. Mick
16
2109
by: chris | last post by:
im new to javascript but slowly getting better what i want to do is have some text on the screen and when an event happens for example click a button the text would change to what i want. how would i do this ??
2
2359
by: celtique | last post by:
Hello everybody! I've just registered to this forum and yet got a question. :) I've got some database, that is processed by PHP in a 'while' loop and each element that the loop draws (<li>) gets an unique ID and href to the javascript function, that should change its background color and post the ID to some invisible <input>. Actually it works...
3
1749
by: naurus | last post by:
I have some code that must change the onclick function of a DIV: function navChange(id,auto){ check = fetchById(id + "More").style.display; if(check == "block"){ showLess(id,auto); } else{ showMore(id,auto); } }
0
7583
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...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6255
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...
1
5484
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...
0
5213
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.