Javascript til styring af hvilken af 2 <DIV> der vises
fejlen jeg får hedder:Line: 47
Char: 1
Error: Objekt exspected
code: 0
jeg antager at det er mit hiddenfield der ikke fanges af javascriptet, håber der er et klogt hovede der kan hjælpe...
Jeg bruger Visual Web Developer 2005
koden:
-----------
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.HiddenField1.Value = "false"
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.HiddenField1.Value = "true"
End Sub
</script>
<script language=javascript>
function checkBrowser(){
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
return this
}
bw=new checkBrowser()
//Shows the div
function show(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.visibility='visible'
}
//Hides the div
function hide(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.visibility='hidden'
}
Function Test()
{
if( document.form1.elements["hiddenfield1"].value == 'true' )
{
alert('Vis Test!');
show('test')
}
if( document.form1.elements["hiddenfield1"].value == 'false' )
{
alert('Vis Test1!');
show('test1')
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body onload="Test();">
<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" Value="true" />
<div id= "test" style="visibility: hidden; display: none;">
vis mig <br />
<Table ID="Table1" runat="server">
<tr><td>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td></tr>
</Table>
</div><br />
<div id="test1" style="visibility: hidden; display: none;">
Vis ikke mig<br />
<Table ID="Table2" runat="server">
<tr><td>
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" /></td></tr>
</Table>
</div>
</form>
</body>
</html>