Jump to content

target a particular box of an input array


ajoo

Recommended Posts

Hi all !

I have created an array of input boxes and i wish to target each individually to check its contents after the user has input some values and pressed the click button.

I have a fiddle at  http://jsfiddle.net/crnsbz5a/13/

When the button is clicked, I want to compare the values of the input fields against the "a" array. If there is a mismatch I want to change the background color of the input box to a different color. 

I cannot figure out how to target the individual input box. 

Thanks all ! 

 

Link to comment
Share on other sites

Before that, you know you're wrapping each input in its own form, right? Separately?

You're creating the inputs and forms dynamically. Add an event listener to the form you make so that when it's (attempted to be) submitted that it checks the input against the item in the array. The only awkwardness is the array variable being reused so you can't use it in a closure, so instead of that try Array.map() like

a.map(function(value, key) {
	// ...
});

 

Link to comment
Share on other sites

Hi Requinix !

Quote

Before that, you know you're wrapping each input in its own form, right? Separately?

Now that you point it out, I can see it ? ! Thanks ! And now that you told me, kindly help me resolve it as that as well !

I couldn't get the map function to resolve the issue so i used this instead :

$.each(test_arr, function(i, item) { ... });

So please help me wrap all the fields in a single form so that they may be submitted with a single button click.

Thanks loads !

Link to comment
Share on other sites

Hi !

I am creating everything through javascript, since the number of fields are dynamic in the sense that they can change. I can need all the way from 10 to 20 fields and depending on that I would need to set them with different font and ( box ) size settings to have a proper page layout. 

Is it not a good idea to use JS to create the page ?

What would you suggest?

Quote

map, each, same difference.

I think you mean that I should use map to get all the values ( that i have already tried out ) and then use for each on that to target the values one by one. correct ?

Thanks !

Edited by ajoo
Link to comment
Share on other sites

Are you not using PHP? If you needed to add or remove fields after the page loaded, that's one thing, but if you know ahead of time then you should do all the work in PHP and deliver the completed result to the browser without it having to perform additional work.

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.