?
Solved

jquery multiple selector options.

Posted on 2013-10-28
4
Medium Priority
?
411 Views
Last Modified: 2013-10-30
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
Comment
Question by:rivkamak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:zappafan2k2
ID: 39607681
$('#'+data.field).val()
should return the value of the element whose id matches the value of data.field
0
 

Author Comment

by:rivkamak
ID: 39607724
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
 
LVL 12

Accepted Solution

by:
zappafan2k2 earned 2000 total points
ID: 39607734
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
 

Author Comment

by:rivkamak
ID: 39607744
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

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question