Filling inputs again and again

Take a look at this fiddle…the (business) user of a web app is requested to fill services names in the inputs you see…

I am in the process of performing various tests in the form and as a result of this I must fill the inputs again and again…so I am trying to find out if there is any way I can automate this.

You have any ideas?

var fields = ['hair','55.00','manikiour','55.00','test','55.00']
$('.text').val(function(i,e) { return fields[i] })

how(or from where) I will execute this code?

Alternatively, you can stick it into the actual page’s code for the time being to test with.

That is what I thought…but take a look what happens.
image snapshot

You’ve got more fields in there than those you showed me in the fiddle. So it’s written things into the first 6 fields with the “text” class. Specifically, there are 16 elements with “text” as a class.

So lets try more specific.

$('.services').val(function(i,e) { return ['hair','manikiour','test'][i] })
$('.price').val(function(i,e) { return ['0.13','0.14','0.15'][i] })

It is OK now but some answers are needed…
How the h…l were you able to figure out that there are 16 elements with class text.
Did you figure it out from the console screenshot?

I just pasted your fiddle HTML into my editor and counted them. That said, some were commented out and therefore not relevant, which reduced the number to 12, but 6 of those were in a type="text" attribute, leaving 6 as class="text".

the console screenshot told me the number. “m.fn.init(16)”… there were 16 things that matched your selector.

by the way… what m.fn.init means?

I’m not entirely sure what the ‘m’ comes from, possibly a jquery definition for it’s class… but essentially it’s the generic function (fn) calling init (because it’s initializing an object, in this case, the selector).

One last thing…(my mistake I did not mention it earlier).The code you gave is about filling service and price inputs…additional code is needed for selecting also an for the radio buttons-you can see these in the fiddle too…click edit and the radio buttons are located on the right of the inputs.

So to do that, you’d have to click the edit button, wait until it renders the objects, and then check the radio buttons.
Here’s a breakdown of that sentence:

jQuery exposes a .click() method.
Waiting would be just a momentary pause (setTimeout)
The radio button array can be referenced as $('.show_price') [Alternative method of pause: Check for a member of that selector to satisfy the Visible selector]
Radio buttons react to their .val() being set.

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