Solved

jquery multiple selector options.

Posted on 2013-10-28
4
404 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
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

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

Author Comment

by:rivkamak
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now