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>