|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
||||
|
||||
|
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);" /> ... |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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? |
|
#6
|
|||
|
|||
|
Quote:
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! |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
Dude, you're awesome!!!!!!!! Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
#9
|
||||
|
||||
|
it's not over until it's over - no need to thank me until you check it and it works.
![]() |
|
#10
|
|||
|
|||
|
Quote:
|
|
#11
|
||||
|
||||
|
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... ![]() |
|
#12
|
|||
|
|||
|
Code:
var objCombo=objButton.form.elements[strComboName]; Can you tell me what this line does? Thanks! |
|
#13
|
||||
|