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 8828725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:40:23+00:00 2026-06-14T07:40:23+00:00

I have a JavaScript variable imgIndex that I’d like to send to an <a

  • 0

I have a JavaScript variable imgIndex that I’d like to send to an <a href="..."> so I can change the id based on imgIndex

Javascript:

<script type="text/javascript">

var imgArray = [<?php echo implode(',', getImages($cat, $site)) ?>];
window.imgIndex = <?php echo $imgid ?>;

$(document).ready(function() {      

    var img = document.getElementById("showimg");
    img.src = imgArray[<?php echo $imgid ?>];

    $(document).keydown(function (e) {
        var key = e.which;
        var rightarrow = 39;
        var leftarrow = 37;
        var random = 82;

        if (key == rightarrow) 
        {
            imgIndex++;
            if (imgIndex > imgArray.length-1) 
            {
                imgIndex = 0;
            }
            img.src = imgArray[imgIndex];
        }
        if (key == leftarrow) 
        {
            if (imgIndex == 0) 
            {
                imgIndex = imgArray.length;
            }
            img.src = imgArray[--imgIndex];
        }
        if (key == random) 
        {
            imgIndex = Math.floor((Math.random()*(imgArray.length-1))+1);
            img.src = imgArray[imgIndex];
        }   

    });
});

</script>

HTML:
Then send imgIndex here so the id of the image will equal imgIndex:

<a href="?action=viewcomic&id=imgIndex"><img id="prevkey" src="./images/SiteDesign/prev.png" alt="Comic Navigation" /></a>

But it doesn’t work.

Any suggestions on how to pass it to <a href="...">?

EDIT:

The reason I can’t use is because I need to manipulate a javascript variable, not a number (as the browser renders the php value).

  • 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-14T07:40:24+00:00Added an answer on June 14, 2026 at 7:40 am

    You can manipulate the target of the link after you are done processing imgIndex.

    document.getElementById("yourLinkId").href = "?action=viewcomic&id=" + window.imgIndex;
    

    Other than that, you can append an event handler to the link, which I am showing here as a sample for jQuery:

    $("#yourLinkId").on("click", function()
    {
        $(this).attr("href", "?action=viewcomic&id=" + window.imgIndex);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript variable: var foo='<script type=text/javascript>alert(Hello World);<\/script>' The variable is inserted with
I have a boolean JavaScript variable named foo that I would like to change
I have javascript string variable with var sttr=We prefer questions that can be answered
I have a JavaScript variable that stores a websocket connection like so: var ws
I have a JavaScript variable: var text = http://example.com Text can be multiple links.
I have a javascript string variable like so: var somestring = mypattern_var1_var2; How can
I have a JavaScript variable that is storing some values. Can I echo it
I have a paragraph of text in a javascript variable called 'input_content' and that
I have a javascript variable which looks like: data = [{ y: 55.11, color:
So I have a xml document loaded in JavaScript variable. Xml looks like this:

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.