By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Changing a variable with onClick

100+
P: 139
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
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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

P: 4
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

100+
P: 139
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

P: 4
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
Expert Mod 15k+
P: 16,027
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

100+
P: 139
Thanks - i have changed it and it works fine!
Jul 22 '09 #7

Post your reply

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