0
var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
  $(".cross-reference-section-value-id").text(id);
  $(".cross-reference-section-value").text(to_s);
  $(".cross-reference-section-value").css('display', 'inline');
  $("#modal_popup").dialog("destroy");
  $(".cross-reference-clear-img").removeData([id, to_s]);
};

By this javascript, i bring the id and the string and stored into the label field in my html page. Now, I hide the id by the css attribute. I am just to displaying the string. I added a image of clear symbol next to the string. When i click that image, it should clear the both id and string fields and hide the image icon.

0

2 Answers 2

2

Also, a small optimisation: you can concatenate the jQuery functions for speed

$("#cross-reference-section-value")
  .data('id', id);
  .text(to_s);
  .css('display', 'inline');

Even further, save the $("#cross-reference-section-value") in a variable:

var my_div = $("#cross-reference-section-value")
my_div
  .data('id', id);
  .text(to_s);
  .css('display', 'inline');
Sign up to request clarification or add additional context in comments.

1 Comment

$('.cross-reference-clear-img).on('click', function(){ $("#cross-reference-section-value").text('') }
1

It'd be much easier not to hide an id, just to store it in another place instead. For example:

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
    $("#cross-reference-section-value").data('id', id);
                                       .text(to_s);
                                       .css('display', 'inline');
    $("#modal_popup").dialog("destroy");
};

To access this property just use the same .data method:

var id = $("#cross-reference-section-value").data('id');

3 Comments

in the same field i have a button with the class name of .cross-reference-clear-img When we click this image i want to clear the field and make the id and string to the default state. is it possible?
Well, cleaning up the text is trivial (.text('')), and removing data is doubly so: .removeData('id') (doc page). If you were talking about restoring the original line (that was removed with .text(to_s), you can store (and restore) that line with .data as well.
First, you're trying to removeData from the wrong element (not the one you'd attached it to), so it won't work in any case. Second, to do something on click you need to register another function (that will clear both text and data) as clear-img click handler. Finally, it's not quite welcome here trying to squeeze several questions into a single one.

Your Answer

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.