1

I have 2 button and i want to change background image of that button which is clicked.

<input style="float:right; padding-right:10px;" name="comp_sephora" id="comp_sephora" type="submit" value="Sephora" onClick="change(this.style);">

<input style="float:right;" type="submit" name="comp_bloom" id="comp_bloom" value="Bloom" onClick="change(this.style);">

i have used javascript function for that:

function change(style)
{
    //alert(val);
    style.backgroundImage = "url(<?php echo  IMAGES."btn1.bmp"; ?>)";
    //style.color = "#000000";
}

but when i was clicked then image changed for only few seconds. i want to maintain that image after page reload.

2 Answers 2

2

You need to return false to prevent the page from being "submitted".

function change(style)
{
    //alert(val);
    style.backgroundImage = "url(<?php echo  IMAGES."btn1.bmp"; ?>)";
    return false;
}

And then change the onclick to this onClick="return change(this.style);"

Sign up to request clarification or add additional context in comments.

Comments

0

Changing your type from "submit" to "button" should do the trick.

Hope this helps,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.