See my demo page for where I have it working on an img src but not an input which is what I really want.

Here's the link to my testing / demo page: http://www.myu2sig.com/stellardonations/buttontype.php

As for what I want to do, how can I apply the function to the input so it's image changes on the value of the select like the regular image does which uses HTML's img src.

As for all of the code that produces what you see on said page:

<script type="text/javascript">
	function showimage(t){
		if (!document.images)
		return;
		document.images[t.getAttribute("name").replace("select","pics")].src=t.options[t.selectedIndex].value
	}
</script>

Regular Image using: < img name="firstpics" src="/stellardonations/paypaldonate.gif" ><br />
<img name="firstpics" src="/stellardonations/paypaldonate.gif">

<br /><br />

Input Image using: < input name="firstpics" type="image" src="/stellardonations/paypaldonate.gif" border="0" name="submit" ><br />
<input name="firstpics" type="image" src="/stellardonations/paypaldonate.gif" border="0" name="submit">

		<br /><br />
		
		<select name="firstselect" onChange="showimage(this)">
		<option value="/stellardonations/paypalsubscribe.gif">Yes</option>
		<option selected="selected" value="/stellardonations/paypaldonate.gif">No</option>
		</select>
		
		<br /><br />
		
		No = Donate<br />
		Yes = Subscribe

Recommended Answers

All 3 Replies

Ps; I know I have name="" twice on the input, that was a typo but the fact remains I would like to apply the image change to the inputs source based on the selected value of the drop box.

Do you mean you want to cooperate 'input' tag with a function call? You can use onclick() event.

//i.e. in javascript
<script type="text/javascript">
function clickItAlready(arg1Str, arg2Num) {
  alert(arg1Str+":"+arg2Num)
}
</script>

// in HTML
<input type="image" src="/stellardonations/paypaldonate.gif" border="0" name="submit" onclick="clickItAlready('my string argument', 777)">

What I want to is is have the inputs image change based on the selection of the select box. So if Yes is chosen the inputs image changes o a subscribe button and if No is ticked the input remains a donate button.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.