Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:54:24+00:00 2026-06-17T08:54:24+00:00

How can I modify this script to capture the ‘alt’ attribute for the images

  • 0

How can I modify this script to capture the ‘alt’ attribute for the images a user selects in a slideshow?

This code displays a series of 20 pairs of images and asks users to select their preferences. Each time the user clicks one of the ‘Select’ buttons, the ‘manipulateDOM()’ function advances to the next set of items in the the text and image arrays. However, since it’s not set up as a typical form field, I’m having difficulty figuring out how to capture the value of each selection so that it can be submitted to the database with the rest of the form values.

I tried creating a function with the click() method to (at the very least) capture the src value, but I can’t get the syntax right so that it can run in conjunction with the ‘manipulateDOM()’ function. I’d also much rather capture the ‘alt’ attribute, but I couldn’t figure out how to do that.

Function I was experimenting with:

 $(document).ready(function () {
     $("#buttons").click(function () {           
         var imgvalue = $("#imgtrendy").attr("src");
         $("#picval").text(imgvalue);
         document.write(imgvalue + ', ');
     });
 });

Existing Code:

Javascript – manipulateDOM() and manipulateDOM1() functions

 var NumberOfImages = 3 - 1; //-1 because array members starts from 0
 var trendy = new Array(NumberOfImages);
 trendy[0] = "files/set1/A1.jpg"; 
 trendy[1] = "files/set1/B1.jpg"; 
 trendy[2] = "files/set1/C1.jpg";
 var imgNumber = 1; //array key of current image

 var NumberOfImages = 3 - 1;
 var classic = new Array(NumberOfImages);
 classic[0] = "files/set1/A2.png"; 
 classic[1] = "files/set1/B2.jpg"; 
 classic[2] = "files/set1/C2.jpg";
 var classicNumber = 1;

 var text = 3 - 1;
 var text = new Array;
 text[0] = "Which would you be more likely to wear?"
 text[1] = "Which look is more you?"
 text[2] = "Which would you rather wear?"
 var textNumber = 1;   

function manipulateDOM() {
     changeObjects();
     NextImage();
 }
 function changeObjects() {
     document.getElementById("question").innerHTML = text[textNumber];     
 }   
 function NextImage() {
     if (imgNumber < NumberOfImages) //Stop moving forward when we are out of images
     {
         imgNumber++;
         document.images["taste"].src = trendy[imgNumber];
         document.images["taste1"].src = classic[imgNumber];
         textNumber++;  
         document.getElementById["question"].innerHTML = text[textNumber];
         document.getElementById["selectButton"].innerHTML = text[textNumber];
     }   
 }    
 function manipulateDOM1() {
     changeObjects();
     NextImage1();
 }
 function NextImage1() {
     if (imgNumber < NumberOfImages)
     {
         imgNumber++;
         document.images["taste"].src = trendy[imgNumber];
         document.images["taste1"].src = classic[imgNumber];
         textNumber++;  
         document.getElementById["question"].innerHTML = text[textNumber];
         document.getElementById["selectButton"].innerHTML = text[textNumber];
     } 
 } 

HTML

<form id="taste" name="taste" method="post" action="taste-exec.php" >
<h2 id="question"> Which would you be more likely to wear?</h2>
<table><tr>
   <td><img id="imgtrendy" src="files/set1/A1.jpg" name="taste" value="trendy[1]" /></td>
   <td><img id="imgclassic" src="files/set1/A2.png" name="taste1" value="classic[1]"  /></td></tr>
<tr id="buttons">
   <td><img id="trendyButton" alt"Select" src="files/Select.jpg" onclick="javascript:manipulateDOM()"></td>
   <td ><img id="classicButton" alt"Select" src="files/Select.jpg" onclick="javascript:manipulateDOM1()"></td> 
</tr><tr>
   <td id="picval"></td>
   <td><input name="answer" id="answer" type="text" /></td>
</tr></table>
</form>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:54:25+00:00Added an answer on June 17, 2026 at 8:54 am

    You get the alt attribute using also the attr method and alt as parameter, just like you are already doing with src. You could try:

     function changeObjects() {
         document.getElementById("question").innerHTML = text[textNumber];     
    
         var imgvalue = $("#imgtrendy").attr("alt");
         $("#picval").text(imgvalue);
     }   
    

    Edit: Example of keeping data in one single array

    //to save it
    var alt = $("#imgtrendy").attr("alt");
    var fileName= 'someValue';//populate accordingly
    var myArray[index] = alt + '|' + fileName;
    //to retrieve it
    var bothValues = myArray[index].split('|'); //gives you an array
    alt = bothValues[0] //contains alt at index 0
    fileName = bothValues[1] //contains fileName at index 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
Looking at this jQuery example, how can I modify the code so that it
I have an app that can make modify images. In some cases, this makes
I'm trying to modify this code ( http://code.google.com/p/pypng/source/browse/trunk/code/texttopng ) so that it can render
How can I modify this script to encase the AM/PM text in a div?
How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
I am having following class hierarchy - //Abstract Class1 in library1 (Can't modify this)
In android the Toggle buttons are looks like below - Can we modify this
Can someone tell me how to modify this regex to allow periods in a
Hy everyone i've been trying for 2 days to modify this script so i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.