Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to refference an element.

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
I have the following function which is triggered by an onchange event.

Code:
	function ObjChanged(OC)
		{

			document.getElementById(OC).value = "1";

		}

The param that is sent is the id of a hidden element that I want to set from 0 to 1 so that I know that a change has been made.

Basically I have a form that is created in asp so that each dropdown has it's own hidden change element when the dropdown is changed the script should kick in and set the value of the hidden element WxDxChanged to 1

Sample of the html that is produced by the asp....

Code:
<tr>
	<td class="InOutDT">
		Tue&nbsp;15/9
		<input type="hidden" name="W1D2ActualD" id="W1D2ActualD" value="15/09/2009" />
		<input type="hidden" name="W1D2Changed" id="W1D2Changed" value="0" />
	</td>
	<td class="InOutAM_L">
		<select name='W1D2AMV' id='W1D2AMV' onchange='ObjChanged(W1D2Changed)' >
			<option value='IN' selected='selected'>IN</option>
			<option value='NA' >Not Available</option>
			<option value='OUT' >OUT</option>
		</select>
	</td>
	<td class="InOutAM_L">
		<select name='W1D2PMV' id='W1D2PMV' onchange='ObjChanged(W1D2Changed)' >
			<option value='IN' selected='selected'>IN</option>
			<option value='NA' >Not Available</option>
			<option value='OUT' >OUT</option>
		</select>
	</td>
	<td class='InOutNote_L'>
		<input type='text' size='95' maxlength='120' name='W1D2NoteV' id='W1D2NoteV' value='' />
		<input type='hidden' name='W1D2ResetD' id='W1D2ResetD' value='16/09/2009' />
	</td>
</tr>
<tr>
	<td class="InOutDT">
		Wed&nbsp;16/9
		<input type="hidden" name="W1D3ActualD" id="W1D3ActualD" value="16/09/2009" />
		<input type="hidden" name="W1D3Changed" id="W1D3Changed" value="0" />
	</td>
	<td class="InOutAM_L">
		<select name='W1D3AMV' id='W1D3AMV' onchange='ObjChanged(W1D3Changed)' >
			<option value='IN' selected='selected'>IN</option>
			<option value='NA' >Not Available</option>
			<option value='OUT' >OUT</option>
		</select>
	</td>
	<td class="InOutAM_L">
		<select name='W1D3PMV' id='W1D3PMV' onchange='ObjChanged(W1D3Changed)' >
			<option value='IN' selected='selected'>IN</option>
			<option value='NA' >Not Available</option>
			<option value='OUT' >OUT</option>
		</select>
	</td>
	<td class='InOutNote_L'>
		<input type='text' size='95' maxlength='120' name='W1D3NoteV' id='W1D3NoteV' value='' />
		<input type='hidden' name='W1D3ResetD' id='W1D3ResetD' value='17/09/2009' />
	</td>
</tr>

The error I'm getting is...
Object Expected and points to the line with the onchange event that was used.

Any help appreciated

I've not failed! Just found 100 ways that don't work...yet!
 
Hi

I see no declaration of the W1D2Changed variable, bu you are using it like a variable. Use it as a string :
Code:
<select name='W1D2AMV' id='W1D2AMV' onchange='ObjChanged([red]"[/red]W1D2Changed[red]"[/red])' >

Feherke.
 
Thanks Feherke,

I'll see what I can do to change the asp. The HTML is generated via asp and hence the use of single quotes in the name and id... would
Code:
<select name='W1D2AMV' id='W1D2AMV' onchange='ObjChanged('W1D2Changed')' >
work? Or should I use &#34; as quotes?

Mych

I've not failed! Just found 100 ways that don't work...yet!
 
Hi

Mych said:
The HTML is generated via asp and hence the use of single quotes in the name and id...
I see no relation between the language used to generate it and the output. I know no programming language unable to output a double quote character.
Mych said:
would
Code:
<select name='W1D2AMV' id='W1D2AMV' onchange='ObjChanged('W1D2Changed')' >
work?
No. The first single quote will end the value :
Code:
<select name='W1D2AMV' id='W1D2AMV' onchange=[highlight]'ObjChanged('[/highlight]W1D2Changed[highlight]')'[/highlight] >
Mych said:
Or should I use &#34; as quotes?
That will work. But I would write it as [tt]&quot;[/tt] to keep it human readable.

Feherke.
 
Feherke,

Thanks for reply... going a bit off topic but here is the line from asp that generates the select tag...
Code:
							Response.Write("<select name='" & Lookup & "AMV' id='" & Lookup & "AMV' onchange='ObjChanged(" & LookUp & "Changed)' >")
As the double quotes are part of the Response.Write I can't use them directly. LookUp is generated programmatically to give me W1D1, W1D2, W1D3...W2D1...W2D5 where W is week and D is Day. If you havn't guessed I producing and electronic In Out board displaying the whereabouts of the team over the next two weeks.

I'll try
Code:
								Response.Write("<select name='" & Lookup & "AMV' id='" & Lookup & "AMV' onchange='ObjChanged(&quot;" & LookUp & "Changed&quot;)' >")
to see if that helps.
Thanks

I've not failed! Just found 100 ways that don't work...yet!
 
Hi

Mych said:
As the double quotes are part of the Response.Write I can't use them directly.
Certainly you can. As far as I know, you have to double them :
Code:
Response.Write("<select name='" & Lookup & "AMV' id='" & Lookup & "AMV' onchange='ObjChanged([highlight]""[/highlight]" & LookUp & "Changed[highlight]""[/highlight])' >")


Feherke.
 
Ok,

Have used your response.write and the html produced is now
Code:
<select name='W1D3AMV' id='W1D3AMV' onchange='ObjChanged("W1D3Changed")' >

I even tried
Code:
<select name='<%=LookUp%>AMV' id='<%=LookUp%>AMV' onchange='ObjChanged("<%=LookUp%>Changed")' >
[i]and[/i]
<select name="<%=LookUp%>AMV" id="<%=LookUp%>AMV" onchange="ObjChanged('<%=LookUp%>Changed')" >
Both give what looks like good syntax html.

Unfortunately all three give the same JS error Object expected... Just can't figure out why!

I've not failed! Just found 100 ways that don't work...yet!
 
Ok, Not sure what went wrong but have fixed it.

Originally, my script was an external file that I referenced to within the <head> tags using
Code:
  <script type="text/javascript" src="jscript/ObjChange.js"></script>
changed it to
Code:
<script type="text/javascript">
	function ObjChanged(OC)
		{
			document.getElementById(OC).value = "1";
		}
</script>

and it now works no problem...

Thanks for your help.

I've not failed! Just found 100 ways that don't work...yet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top