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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:00:17+00:00 2026-06-04T05:00:17+00:00

I want to set up an image button (OPEN) with an onclick() function that

  • 0

I want to set up an image button (OPEN) with an onclick() function that renders a message including specific value changes in php.
The desired behaviour when user clicks on that button, is that it will be replaced with another image button (CLOSE).

Is it possible to set a variable button ?
I have attempted to use variable link as follows:

JavaScript:

if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
   }
 else
 {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function()
 {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
   var response=xmlhttp.responseText;
   x=response;
   if(x == 1)
   link="OPEN";
   else 
   link="CLOSE";

   var content = "<table style=\"padding-left:10px ;  float:right ; text-align:right\" > <tr><td style=\"float:right;color: blue;text-decoration: underline\" onmouseover=\"this.style.cursor='hand'\" onclick=\"function()\">"+link+"</td></tr></table>";

But, when user click on the ‘OPEN’ link and closes the page, next time he will get the CLOSE link instead of OPEN

Any suggestions on how to implement this correctly?

  • 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-04T05:00:18+00:00Added an answer on June 4, 2026 at 5:00 am

    something like this

    if(x == 1) {
      link="OPEN";
      src="open.png"
    } else {
      link="CLOSE";
      src="close.png"
    }
    
    var content = "<table style=\"padding-left:10px ;  float:right ; text-align:right\" > <tr><td style=\"float:right;color: blue;text-decoration: underline\" onmouseover=\"this.style.cursor='hand'\" onclick=\"function()\"><img src=\""+src+"\"/>"+link+"</td></tr></table>";
    

    or use with an image somewhere

    document.getElementById("imageid").src=src
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that contain a image i want to set a button
I want Image button with two state(normal , mouse over). that button must change
I have to create a button programmatically, and set an image background at that
I want to be able to set the background of an image button in
I have one question. I want to set one image to image button. I
I hava a UIButton. And for my button I want to set image with
I want to set a specific background image for all my buttons. So, I
I want to set background image to right and top of my span because
I want to set the thumb image of a slider for a normal state,
I want to set the Expires header for all image/* and text/css . I'm

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.