0

I have asked this question earlier, please click here!

this is extension to the question

This is my jQuery

<script>
$(document).ready(function () {
 $('#TextBox2').blur(function () {
 var objVal = $(this).val();
 if (objVal != '') {
 $('h3 a[class="Anchor2"]').text(objVal);
 }
 else {
 $('h3 a[class="Anchor2"]').text("Default Text")
 }
 });
});

My Markup

<a href="#" class="Anchor2">Default Link Text</a>
<input type="text" size="50" name="Medication2" id="Medication2">

This work fine for the first set of Anchor Link and Text Box

But in my page there is button, when click it will add more sets of Anchor link and Text Box with Unique ID

TextBox1, TextBox2, TextBox3 ....
Anchor1, Anchor2, Anchor3 ..... respectively.

How can I make my Script so work only for specific set.

Like When i have blur event for TextBox3 only Anchor 3 should get affected.

And this should be independent of each set.

asked Oct 12, 2011 at 15:02

1 Answer 1

1

String manipulation:

$(document).ready(function () {
 $('#TextBox2').blur(function () {
 // num will hold the 'number' in the id: 2
 var num = $(this).attr('id').replace("TextBox", "");
 var objVal = $(this).val();
 if (objVal != '') {
 $('h3 a[class="Anchor'+num+'"]').text(objVal);
 }
 else {
 $('h3 a[class="Anchor'+num+'"]').text("Default Text");
 }
 });
});
answered Oct 12, 2011 at 15:06
Sign up to request clarification or add additional context in comments.

5 Comments

What about Initial Selector? $('#TextBox2').blur(function () how will this selector works?
You could use a selector like $('input[id^="TextBox"]').blur(function () {
@ipr101 How can I ask you another question? I am out of my 24 hour limit. can i send a personal message?
@HaBo - Can you ask via another comment?
Please check my question at this link

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.