Solved

add alt attribute value to textbox

Posted on 2014-07-25
6
287 Views
Last Modified: 2014-07-25
http://jsfiddle.net/sevensnake/M5XET/

I need to add a alt tag attribute added to textbox with the ID Value from JSON  (( Example ID":34))
 <input type="text" name="3" id="hold1" autocomplete="off" Value="9000.0000" alt="34">   to the input text box.
see example
0
Comment
Question by:sevensnake77
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40219460
$('#mybox').attr('alt', 'Your text');

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 40219465
http://jsfiddle.net/GaryC123/M5XET/10/

$.each(result.d, function(i, item) {
    $("[name="+this.APT+"]").val(this.hold).attr("alt",this.ID)
});

Open in new window

0
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 250 total points
ID: 40219511
You have a couple things wrong, first your string creating your json are missing " around ID and ntID in your first dimension. You are also using this instead of item with trying to access your attributes of your json.  Finally you are not parsing your result into json before trying to access it.

result= {d:'[{"ID":34,"ntID":20006,"APT":3,"hold":9000.0000},{"ID":35,"ntID":20006,"APT":9,"hold":3333.0000},{"ID":36,"ntID":20006,"APT":16,"hold":4434.0000},{"ID":38,"ntID":20006,"APT":18,"hold":1234.0000}]'};

$.each($.parseJSON(result.d), function(i, item) {
    $("[name="+item.APT+"]").val(item.hold).attr("alt",item.ID);
});

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 58

Expert Comment

by:Gary
ID: 40219557
You don't need to 'parse' it
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40219643
If you do not parse it,  result.d is just going to be a string not an object or array.  Not sure how you would issue a foreach loop on a string.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40219649
tks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
get radio button vale in array 7 44
Populating html form in Sharepoint using JSOM 11 50
JavaScript Scope issue 4 40
Jquery autocomplete 10 68
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

867 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

23 Experts available now in Live!

Get 1:1 Help Now