Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

jquery multiple selector options.

I am trying to get a complex jquery selector statement.
Something along this lines
($('input').attr('id', data.field) );
the selector that  I need is :
the input field on my page. whose attribute ID matched the variable in data.field

but I need as output the value of the attribute 'value' of that specific input field.
how do I combine that together?
0
rivkamak
Asked:
rivkamak
  • 2
  • 2
1 Solution
 
zappafan2k2Commented:
$('#'+data.field).val()
should return the value of the element whose id matches the value of data.field
0
 
rivkamakAuthor Commented:
How do I do the opposite?
the selector should be where the id is the value of the attribute 'data' on the field #popinput
Can i do something like this?
      fieldname = $('#popinput').attr('data-name');
 $(fieldname).attr('value', $('#popinput').val() );
0
 
zappafan2k2Commented:
First, if you want to set the value of an input element, you don't have to use attr(), just use val().  That's what it's there for.

In your example above, you're close.  Try changing it to
fieldname = $('#popinput').attr('data-name');
 $('#'+fieldname).val($('#popinput').val() );

Open in new window

When selecting an element by its id, you have to preface the id with a #, just like in CSS.
0
 
rivkamakAuthor Commented:
Thank you for your help.
In concept it works great..

You can view my page here:
https://www.oorahauction.org/prizes.asp

if you put an quantity in the prize box, then click on the image, it will pop up with more information and the prize box in the popup will have the same amount as the box on the page.

if you change the amount in the popup box, when you close the popup , the field on the main page will adjust to that new amount

yet, when you click on another image, and the box pops open, the input box is still filled out with the amount you put in before, not matching that correct quantity of that prize.but if you check the code, the jquery worked and the value is blank.

Why is the input box showing an old number is the value in the code is really empty?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now