How to get/set a Text Field from JavaScript?

Does anyone know how to do this?

It’s easy for text on regular widgets ($axure(’@widgetName’).text()) but for some reason that doesn’t work on Text Field widgets.

I’m looking for a solution which correctly triggers the Text Changed event.


$axure(’@widgetName’).value() used to work, but apparently that broke at some point in Axure 8.

The only documentation I know of is here.

Yeah, there’s nothing on Sam’s site re TextField, and in RP9 value() returns an empty string.

With some hacking about with the APIs I’ve managed to set some text in its space (but without Text Changed"), but this also makes it not a TextField anymore (so I’m obviously doing something pretty bad and definitely wrong :slight_smile: )

Does anyone else have any suggestions?

For some reason there’s a different method for setting an input’s value:

$axure(‘@widgetName’).$().find(“input”).val(‘New Value’);

The bigger problem is that modifying the DOM via JavaScript won’t fire Axure events so you have to use JavaScript to fire those too. I could get a few events to work (“click”, “focus”, “keyup”, and the like) but the “change” event doesn’t seem to work: GetSet_Input.rp (52.0 KB)

I’m no JavaScript expert so maybe someone else might know how to get it working right.

1 Like

Hi again -

I looked at Axure’s code for setting the text input’s value and it’s obvious why it is broken: they’re applying jQuery’s .val() function on the outer div containing the input rather than on the input itself.

Also, the code that sends the Text Changed message has also been removed, so even if I add code to fix their bug, no message gets sent.

A bit of hacking…

If I supply “true” to change(), I get this:

Does any of that info throw any light on things?
(I didn’t expect either of these to work by the way, but throwing random objects into the machinery is always interesting at least)


Just realised that of course I don’t need a call to get the value, since substitution ( ‘[[LVAR1]]’ ) will do the trick for that.

At least not in many cases. For some dynamic situations only happening within javascript it’s still going to be useful to use the javascript call.

OK - I’ve figured out a way to fire Text Changed events from javascript.

FireTextChanged.rp (47.3 KB)

I think this combined with huban’s $axure(’@widgetName’).$().find(“input”).val(‘New Value’); to set the text should do nicely.


That is what i was searching for from so long, thanks for such information.

You’re welcome.

As you can see, this example doesn’t check to see if it needs to fire - it just goes ahead and fires it regardless (which is actually more useful in some circumstances), and it’s only a couple of lines of javascript if you wanted to write a little function that checked the text first to see if it needed firing.

I just figured that this “raw” version would be what most people would want to start from.


The relevant bit of code (for those who don’t want to download the example) is this:
(where MyTextField is the name of your TextField widget)


var elementId = $axure('@MyTextField').getElementIds();

$axure.internal (
    function(ax) {
        ax.event.raiseSyntheticEvent(elementId[0], 'onTextChange'); 
        return ax;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.