HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 15th, 2004, 11:16 AM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
function to get name of form item

Ok, I'm trying to write a function that will enable a drop down list when the user clicks a button. My problem is that I have 80 buttons and 80 drop down lists. I am trying to find out if there is a way to write a function that will use a different drop down list name according to the name of the button. I have a very simple function that does the job, but I'd have to have 80 functions. Since I'm not too familiar with javascript I thought I'm post my question here.

Here is what I have:
My button names are: btnSponsor_1, btnSponsor_2, btSponsor_3, ..., btnSponsor_80

I'm calling the following function using the onClick atribute of btnSponsor_1.

function enablefield()
{
document.UpdateForm.ddlSponsor_1.disabled=false;
}

I guess my question is how do I make the # in ddlSponsor_# match # from btnSponsor_# inside the function. So if I click btnSponsor_4, I'd enable ddlSponsor_4, if I click btnSponsor_5, I'd enable ddlSponsor_5 and so on.

Thanks!

Reply With Quote
  #2  
Old November 15th, 2004, 10:15 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
When you call your function have the # as an argument to the function. That way you could have a function that looks like:

function enablefield(intNumber)
{
document.UpdateForm.elements["ddlSponsor_" + intNumber].disabled=false;
}
__________________
If you found a post of mine helpful, please click on the on my post to add to my reputation.


Reply With Quote
  #3  
Old November 16th, 2004, 05:57 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
such code would work for any button:
Code:
<script>
  function enablefield(objButton)
  {
   var strName=objButton.name;
   var arrTmp=strName.split("_");
   var index=arrTmp[1];
   var strComboName="ddlSponsor_"+index;
   var objCombo=objButton.form.elements[strComboName];
   objCombo.disabled = false;
  }
</script>


and the buttons would look like this:
<input type="button" name="btnSponsor_1" value="enable combo 1" onclick="enablefield(this);" />
<input type="button" name="btnSponsor_2" value="enable combo 2" onclick="enablefield(this);" />
...

Reply With Quote
  #4  
Old November 16th, 2004, 08:35 AM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
Shadow Wizard, you're not only quick but your code rocks!!!! Thanks!!!!

Is it possible to get the value of an item that is disabled using Request.Form? Like this:
request.form("ddlsponsor_1") when ddlsponsor_1 disabled="true"

The deal is, user's should only be able to change the value of the ddlsponsor_# if they click the button btnSponsor_# to see the documents for that ddl. I did some searches on google and Memmoch was suggesting to use a hidden field and then use Request.Form("hdnddlSponsor_#"). My problem is that if the user changes the value of the ddlSponsor_#, I need to get the ddlSponsor_# value and not the hdnddlSponsor_# value. Does that make sense?

Thanks!

Last edited by maxtrixx : November 16th, 2004 at 09:16 AM.

Reply With Quote
  #5  
Old November 16th, 2004, 09:29 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
well, this time I wasn't quick. but I'm glad you like my code...
disabled item's value would be sent as usual, as far as I know... if you want you can change the combo box selection when you disable it.
anyway, I didn't understand the problem - what exactly do you want, what you have so far and what is not working?

Reply With Quote
  #6  
Old November 16th, 2004, 09:44 AM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
Quote:
Originally Posted by Shadow Wizard
well, this time I wasn't quick. but I'm glad you like my code...
disabled item's value would be sent as usual, as far as I know... if you want you can change the combo box selection when you disable it.
anyway, I didn't understand the problem - what exactly do you want, what you have so far and what is not working?

Ok, here is my problem, when the page loads for the first time the items have the following states:

<select name="ddlSponsor_1" disabled="true" value="<% = rsSponsor("task_1")%>">
<select name="ddlSponsor_2" disabled="true" value="<% = rsSponsor("task_2")%>">

Using your code, which works very well, I'm changing the disabled state to "false" whenever the user clicks the correpondign button. That is, if the user clicks <input type="button" name="btnSponsor_2"> the disabled state of <select name="ddlSponosr_2"> changes to "false" and I get <select name="ddlSponsor_2" disabled="false">. Now, this is an update form. The update code looks like the following:

SQL = "UPDATE tblProjects SET task_1 = '" & Request.Form("ddlSponsor_1") & "', task_2 = '" & Request.From("ddlSponsr_2") & "' WHERE ProjectID = " & ProjectID & ""

Now suppose the disabled state of <select name="ddlSposnor_1"> is true, that is <select name="ddlSponsor_1" disabled="true">, I don't get any values. So my query becomes:

SQL = "UPDATE tblProjects SET task_1 = ' ', task_2 = 'task completed' WHERE ProjectID = " & ProjectID & ""

However, I still need to get the value of each and every item in my form, even though they are disabled.

I hope this makes sense.

Thanks again!

Reply With Quote
  #7  
Old November 16th, 2004, 09:50 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
if that's the case, you can simply enable all the combos before submitting. add this to your form tag: (add the onsubmit part)
<form action="edit.asp" onsubmit="EnableAll(this);">
and have such code:
Code:
 <script>
   function EnableAll(objForm)
   {
    for (var i=0; i<objForm.elements.length; i++)
 	  objForm.elements[i].disabled = false;
    return true;
   }
 </script>
 


this would cause all combos to become active just before the form is being sent.

Reply With Quote
  #8  
Old November 16th, 2004, 09:54 AM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
Dude, you're awesome!!!!!!!! Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Reply With Quote
  #9  
Old November 16th, 2004, 09:58 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
it's not over until it's over - no need to thank me until you check it and it works.

Reply With Quote
  #10  
Old November 16th, 2004, 10:03 AM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
Quote:
Originally Posted by Shadow Wizard
it's not over until it's over - no need to thank me until you check it and it works.
It does work!!

Reply With Quote
  #11  
Old November 16th, 2004, 10:13 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1Folding Points: 341806 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
oh... no problem then.
these things are so simple for me, I hope you're learning some js as well and will be able to help others in similar cases. I won't be here forever...

Reply With Quote
  #12  
Old November 22nd, 2004, 01:33 PM
maxtrixx maxtrixx is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: ASP Free Forums
Posts: 372 maxtrixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 35 m 13 sec
Reputation Power: 5
Code:
var objCombo=objButton.form.elements[strComboName];


Can you tell me what this line does?

Thanks!

Reply With Quote
  #13  
Old November 22nd, 2004, 01:58 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)