Accessing <input type=image > control in script

I have a problem in accessing the following control
<input type=image name=xyz src=xyz.gif value="insert">
When i want to refer it with its name as follows

<script>
document.frmsamp.xyz.src="abc.gif";
document.frmsamp.xyz.value="Update";
</script>

It shows an error : null or not an object.
ParamaguruAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
oops, forgot the return false; at the end of the onClick:

onClick="document.images['submit'].src='update.gif';document.myform.myhidden.value='update';document.myform.submit();return false;">
0
 
ParamaguruAuthor Commented:
I have used <input type=image> for form submit.
But it shows error when i want to change that "src" attribute and value attribute in form load event in script.
0
 
COBOLdinosaurCommented:
Image type inputs are an alternate to submit.  They act the same way and their attributes are not exposed to scripting.  The value would be ignored in any case.  If you want to dynamically modify the image you will need to use an image link.

Cd&
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
brunoCommented:
not sure how the "value" attribute is even used on an input type="image"....


BRUNO
0
 
knightEknightCommented:
Cd& is correct ... here is the proof:

<HTML>
<HEAD>
<SCRIPT language='javascript'>

function onLoadHandler(theForm)
{
  alert(theForm.elements.length);  // shows that the image is not an element of the form

  var s="";
  for ( o in theForm )
     s+=o+", ";
  alert(s);   // shows all other form properties, none of which is the image
}

</script>
</head>

<BODY onLoad='onLoadHandler(document.myform);'>

<FORM name='myform'>
 <INPUT type='image' name='YYZ' src='YYZ.gif' value='insert'>
</form>

</body>
</html>



so the solution (as Cd& pointed out) would be to use a linked-image and a hidden field to store your "insert" or "update" values:

<A href="Submit" onClick="document.images['submit'].src='update.gif';document.myform.myhidden.value='update';document.myform.submit();">
<IMG name='submit' src='insert.gif'>
</a>
0
 
COBOLdinosaurCommented:
I believe that the value sent for an input image is the x/y co-ordinates in the image.

Cd&
0
 
knightEknightCommented:
value sent to the server, correct ... but this is not accessible via client script.
0
 
malcxCommented:
note that the x/y can be sent as 0, which == false in some server languages...
0
 
COBOLdinosaurCommented:
Paramaguru,

Is there some reason you are ignoring the experts trying to help you?

Cd&
0
 
brunoCommented:

Hello,

This question has been open for quite a while now and needs to be wrapped up.

EXPERTS: If any of the experts could come back and post any suggestions as to how they feel this could be wrapped up (delete, 0 PAQ, award points, etc), I'm sure the moderators would appreciate it.  If you feel you deserve points here, but don't care to respond, the question might very well get DELETED.

ASKER:  Please return and finalize this question.  Abandoning a question is in violation of the member agreement.

Please do NOT accept this comment as an answer, as I am simply trying to alert those involved that the question is still open.

Thank you,

BRUNO
0
 
COBOLdinosaurCommented:
I gave the correct answer and the appropriate option.  Solution in 38 minutes and still no user responses :^(

Cd&
0
 
knightEknightCommented:
agree, points to Cd& IMO
0
 
COBOLdinosaurCommented:
????

Cd&
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.