JS img.match

willsherwood
willsherwood used Ask the Experts™
on
I need help debugging a line of code that's giving an error.

function chgState (objElement)
{
...
var imgID=img.match(/(\d+)\.(gif|jpg)$/i);
...
}

call to the above function:
<span onClick="chgState(this)"><img src="images/1.gif"><input type="hidden" name="A_1" > </span>


error reported by error console

Error: img.match is not a function


any advice for how to resolve?
thanks

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
match will work with string...

get the src of img and do the match.... something like this...


ar imgID=img.src.match(/(\d+)\.(gif|jpg)$/i);
Try
function chgState (objElement)
{
...
var imgID = document.getElementById('img').src.match(/(\d+)\.(gif|jpg)$/i);
...
}
 
<span onClick="chgState(this)"><img id="img" src="images/1.gif"><input type="hidden" name="A_1" > </span>

Open in new window

Commented:
var imgID=img.match(/(\d+)\.(gif|jpg)$/i);
to
var imgID=objElement.src.match(/(\d+)\.(gif|jpg)$/i);

if that does not work send me an URL

Author

Commented:
thanks to all!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial