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.
zachvaldezAsked:
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.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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

0
zachvaldezAuthor Commented:
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?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

zachvaldezAuthor Commented:
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.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, let's say in your MasterPage you got this label control named Label1.

<asp:Label ID="Label1" runat="server" Text="Label" ClientIDMode="Static"></asp:Label>

Open in new window

(make sure ClientIDMode = "Static")

then to change this in child page, you can try:

<ul class="tabs" id="thistab" runat="server">

                <li class="tab-link current" data-tab="tab-1" id="tab11" data-toggle="tab"><a href="#Person" onclick="return setText('Label1',this.text);">Personal Information</a></li>

                <li class="tab-link" data-tab="tab-6" id="tab16"><a href="#Info" data-toggle="tab" title="Employee Information" onclick="return setText('Label1',this.text);">Employee Information</a></li>
                <li class="tab-link" data-tab="tab-2" id="tab12"><a href="#Assign" data-toggle="tab" title="Assignment History" onclick="return setText('Label1',this.text);">Assignment History</a></li>
        </ul>

Open in new window


then your javascript function will look like this:

<script type="text/javascript">
    function setText(c, v) {
        document.getElementById(c).innerHTML = v;
        return true;
    }
</script>

Open in new window

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
zachvaldezAuthor Commented:
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.
0
zachvaldezAuthor Commented:
This work so well and indeed reusable!
0
zachvaldezAuthor Commented:
INDEED IT WORKED! You read the question correctly and I understood well your solution
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.