Russ Bradberry
Russ Bradberry

Reputation: 10865

jQuery Dialog and Setting a Textbox Value

so I have a modal dialog i use with jQuery in my asp .net page. I am trying to set a textbox value using jquery. here is some sample code:

<div class="popup-template popup1">
    <div class="content">     
      <input type="text" id="tbX" value="asdf" />
      <input type="button" onclick="$('#tbX').val('TEST VALUE');" value="Input Test" />
      <input type="button" onclick="alert($('#tbX').val());" value="Output Test" />
   </div>
</div>

I already have, in place, the code to move my dialog back within the form tag so this isn't the issue.

If I move the inputs outside of the modal div then everything works fine.

Thanks for your help

-Russ

Upvotes: 0

Views: 3842

Answers (1)

tvanfosson
tvanfosson

Reputation: 532495

Try using Firefox with Firebug ("view generated source") and see if the modal dialog is recreating your DOM for you and renaming the inputs. This would mean that you are accessing the original, now hidden input from the click handler and the new input when typing. If so, you could change how you are getting the text box element to use something like:

$(this).parent('div').find('input[type=text]:first').val(...)

Upvotes: 1

Related Questions