Forum Moderators: open

Message Too Old, No Replies

Javascript breaks when I add hyphen

         

supermanjnk

1:48 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Heres what I have

<script language="JavaScript">
<!--
document.searchcandidate.company-1.focus();
//-->
</script>

as it is right now this works fine, however i have multiple records so when I make it look like this

document.searchcandidate.company-1.focus();

it breaks. I need to have the - in there because I am using php to explode it.

john_k

2:08 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see any difference in your two lines of code.

At any rate, I would guess that javascript is trying to subtract 1.focus() from document.searchcandidate.company. And that causes an error.

supermanjnk

3:41 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



yea that was a mistake the first line shouldn't have the -1

dcrombie

1:18 pm on Jul 23, 2005 (gmt 0)



There are better ways of referencing form elements. Something like this might work:

document.forms["searchcandidate"].elements["company-1"].focus();

;)