0

Based off of this answer, in order to change the value of an input in Facebox, I need to wrap my .val statements in an anonymous function.

My problem is that I can't just do $('#openPopupClicked').click(function() { //.val here }); because I have variables that need to be passed.

How can I change the value of an input field in Facebox while still passing variables ($example) to it?

My code, which does not change the value of the input field; if I use .html, it will add 'example text' to the parent of the input, so I know that it is accessing that field. I don't understand why .val isn't working for it. If I change the input type to hidden, .val works. It just won't change the value for a text input.

<div id="ExamplePopup" style="display: none;">
    <table>
    <tr>
        <td class="label">
            Name:
        </td>
        <td style="font-weight: bold;" class="input">
            <input type="text" size="25" name="ex_name" id="ExName" />
        </td>
    </tr>       
</table>
</div>

<?php $example = "example text"; ?>
<a href="#ExamplePopup" rel="facebox" onclick="$('#ExName').val('<?php echo $example; ?>');">Open The Popup</a>
Community
  • 1
  • 1
Luke Shaheen
  • 4,262
  • 12
  • 52
  • 82
  • Do you have multiple elements on your form which share the id `ExName`? – James Hill Feb 29 '12 at 18:12
  • You will likely need to modify the plugin to give you access to an "open" callback. This is a very common issue with plugins that don't provide hooks to events – charlietfl Feb 29 '12 at 18:37
  • @JamesHill nope - I've tried it on a test page with just this on it. – Luke Shaheen Feb 29 '12 at 18:55
  • @charlietfl Do you have any resources to point me in the right direction on doing this? Do you have an explanation of why .html would work, but not .val? – Luke Shaheen Feb 29 '12 at 18:56
  • quite honestly I've had to modify numerous plugins to add events that anymore I make sure there is a solid API first before using new plugins – charlietfl Feb 29 '12 at 19:07
  • @charlietfl I just am not comprehending why everything but .val works for a text input - .val works on a hidden input, but not text. Doesn't make sense to me. I don't see why an API would be needed for this though, as all it does it wrap the
    in a facebox div.
    – Luke Shaheen Feb 29 '12 at 19:41
  • I don't know the plugin but comments in link you provided suggest it clones the target element. That's why being able to access an open event would help. Likely not difficult to modify plugin for it by finding the open in code, and adding a new option for hte callback to pass in – charlietfl Feb 29 '12 at 19:45

0 Answers0