get value of variable in javascript

I have a script as below (code section).How can I pass the value of nameOfTextBox variable to the function so that the function should appear as below when I view source:
new tcal({
                        // form name
                        'formname': 'calendarForm',
                        // input name
                        'controlname': 'textboxname'
                    });
<script language="JavaScript">
                    var txtDateOfBirth = document.getElementById('txtDateOfBirth');
                    var nameOfTextBox = txtDateOfBirth.getAttribute('name');
                    //alert(nameOfTextBox);
                    new tcal({
                        // form name
                        'formname': 'calendarForm',
                        // input name
                        'controlname': nameOfTextBox
                    });

	            </script>

Open in new window

meoconxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

btdownloads7Commented:
I'm not sure why you are using "new" for your function. Can't you just change it to:
function tcal(nameOfTextBox){
  // form name
  'formname': 'calendarForm',
  // input name
  'controlname': nameOfTextBox
);

Open in new window

0
leakim971PluritechnicianCommented:
Try:
var z = eval("{'formname:'calendar','controlname':'" + nameOfTextBox +"'}";
new tcal(z);
0
meoconxAuthor Commented:
I'm using a javascript calendar library, it's the code to create a calendar instance. The sample code to create a calendar is here:
      <input type="text" name="testinput" />
      <script language="JavaScript">
      new tcal ({
            // form name
            'formname': 'testform',
            // input name
            'controlname': 'testinput'
      });

However, In ASP.NET, I cannot set the name attribute of a textbox but the ID attribute. So I want to get the name of the textbox by its ID, and pass to the constructor. Is it clear?
@leakim971: It cannot solve my problem :(
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

btdownloads7Commented:
OK, have you tried getting the calue directly in the constructor? Your sample script looks wuite different from the one in the original post, so I'll use the original in my example.
<script language="JavaScript">
                    var txtDateOfBirth = document.getElementById('txtDateOfBirth');
                    new tcal({
                        // form name
                        'formname': 'calendarForm',
                        // input name
                        'controlname': txtDateOfBirth.getAttribute('name')
                    });

	            </script>

Open in new window

0
meoconxAuthor Commented:
nope. It appear as below in the source.


var txtDateOfBirth = document.getElementById('txtDateOfBirth');
                    new tcal({
                        // form name
                        'formname': 'calendarForm',
                        // input name
                        'controlname': txtDateOfBirth.getAttribute('name')
                    });

Open in new window

0
btdownloads7Commented:
I don't understand, did you try my suggestion and it didn't work?
0
meoconxAuthor Commented:
yes, it didn't work, because it should display the name of textbox control at position: txtDateOfBirth.getAttribute('name')
Do you understand?
0
Shinesh PremrajanEngineering ManagerCommented:
place a alert box  like

var txtDateOfBirth = document.getElementById('txtDateOfBirth');
alert(" HERE: "+txtDateOfBirth);

If you see a popup with the value something like [Object]

Then as "btdownloads7" suggested it is suppose to work.
0
meoconxAuthor Commented:
let me explain clearly about the javascript calendar control I'm using. Firstly, I must have the name of the textbox which will display the choosen date . The sample code for using it is attached:
In the sample code, the name of textbox is "testinput" and it's passed to the function (I don't know what the function do, I just know that it will display a calendar ).
However,when I embed the code in ASP.NET, I cannot get the name of asp:textbox at runtime but I can get the ID of asp:textbox at runtime, eg: txtDateOfBirth. Now I want to use that ID to get the name of the textbox and pass it to the function tcal.
Are you all clear about it?
      <input type="text" name="testinput" />
      <script language="JavaScript">
      new tcal ({
            // form name
            'formname': 'testform',
            // input name
            'controlname': 'testinput'
      });

Open in new window

0
Shinesh PremrajanEngineering ManagerCommented:
Ok, then do this tweak, do a view source of the loaded page, then search for your text box, check what is the name that is assigned to the text box.  Assign that name to the "controlname"

Thats it,

Hope it helps
0
meoconxAuthor Commented:
the name is dynamically assigned. I thought about that very simple solution before. I think it's surely a bad trick, not a good solution.
0
Shinesh PremrajanEngineering ManagerCommented:
OK, FYI you can place name or the ID of the textbox, its not necessarly the name alone, provided that the Id assigned to this textbox is unique in the form.

'controlname': 'testinput'

can be repalce with

'controlname': 'txtDateOfBirth'

Also could you check the number of forms in the page, and what is the name of the form "CalendarForm', is it typed correctly ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meoconxAuthor Commented:
Thanks, your solution made me understand clearly about my problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.