Avatar of zachvaldez
zachvaldez
Flag for United States of America asked on

A reusable javascript function to assign a value to a control.

I'm looking for a solution and I thought a client side javascript function  will work. This function will assign the text or title value of a tab  to a particular control.
JavaScriptjQueryASP.NET

Avatar of undefined
Last Comment
zachvaldez

8/22/2022 - Mon
Ryan Chong

A function is always "re-usable", that's the purpose we make a piece of codes as a function.

it depends on the functionality what you intend to include.

I guess what you mean is to get the Page Title and put it into a Form field? if yes, you can try:
<html>
<title>whatever ...</title>
<body onload="setText(document.forms[0].Text1)">
<form>
<input id="Text1" type="text" />
</form>
</body>
</html>

<script type="text/javascript">
    function setText(c) {
        c.value = document.title;
    }
</script>

Open in new window

zachvaldez

ASKER
The idea of the script is correct .

10:<script type="text/javascript">
11:    function setText(c) {
12:        c.value = document.title;
13:    }
14:</script>

How would I assign the c.value to a control in MasterPage?
Ryan Chong

How would I assign the c.value to a control in MasterPage?
MasterPage? are you doing this in asp.net?
no idea how and when you gonna call that Javascript function? can you elaborate further to provide info of your "child page" as well?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
zachvaldez

ASKER
Yes , ASP.NET.
The child page has tabs like this
 <ul class="tabs" id="thistab" runat="server">

                <li class="tab-link current" data-tab="tab-1" id="tab11" data-toggle="tab"><a href="#Person">Personal Information</a></li>

                <li class="tab-link" data-tab="tab-6" id="tab16"><a href="#Info" data-toggle="tab"  title="Employee Information">Employee Information</a></li>
                <li class="tab-link" data-tab="tab-2" id="tab12"><a href="#Assign" data-toggle="tab" title="Assignment History">Assignment History</a></li>

Open in new window


Those title will be assign to a  label control in Masterpage when click.
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zachvaldez

ASKER
I think the change is working for the label in the masterpage. I only change text to title attribute. But what if I want to append the value of the current Label1
for example: the current value of Label1 is  'Home/Person 'and I would like to append the the title so it becomes

'Home/Person/Personal Information'  - That is my current location now based on what I clicked.
zachvaldez

ASKER
This work so well and indeed reusable!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
zachvaldez

ASKER
INDEED IT WORKED! You read the question correctly and I understood well your solution