2

In sahi, I'd like to know if it's possible to set the value of a text field using jQuery? When I use the code below in the sahi controller, the field is set and all is good with the world, but when I add that to a script I get an error saying that '$' is not defined.

$('input[name="postal_address"]').val('some value');

How do I rewrite the above so that it is executed properly when my script runs? I'm not too keen to use the relational APIs for this particular page, there's just too much stuff.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

2

There is a form input elements API for sahi called _setValue().

<INPUT type="text" name="textbox_name"
 id="textbox_id"
  class="shaded bigfont"
   value="apple">

And you can set the input field textbox_name the value you want.

_setValue(_textbox("textbox_name"), "*Your Value*");
  • Thanks Sharukh - I totally forgot to mention that the reason I want to hit it directly is because the field gets a sahi index, and it keeps changing, which is driving me mad. – user2143191 May 27 '16 at 10:05
2

Use the following code inside your script:

_eval("jQuery('input[name=\"postal_address\"]').val('some value')");

You can also go-through the following URL to read about the api _eval.

http://sahipro.com/docs/sahi-apis/action-apis.html#_eval

-- Kshitj Gupta

Kshitij Gupta
  • 410
  • 1
  • 3
  • 9
0

because the field gets a sahi index, and it keeps changing

As mentioned, use _eval to execute jQuery, though a better way IMHO would be to use the _in($container) or _near($label) APIs to work around the changing names.

globalworming
  • 757
  • 1
  • 5
  • 33