Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys
Please check this below code and tell me how can I get the value of textbox into javascript function .


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){
 if (showItSwitch) {
   elementToSet.style.display = "inline";
   elementToSet.style.visibility = "visible";
 }
 else{
     elementToSet.style.display = "inline";
     elementToSet.style.visibility = "hidden";
   }
   
 


function hideTable(){
 setElementVisibility(document.getElementById("a"), false, document.getElementById('TextBox1').value);
}

function removeTable(){
 setElementVisibility(document.getElementById("a"), false, call(a));
}

function showTable(){
 setElementVisibility(document.getElementById("a"), true);
}
</script>

<style type="text/css">
<!--
#Layer1 {
    position:absolute;
    width:50px;
    height:39px;
    z-index:1;
    left: 273px;
    top: 177px;
}
#Layer2 {
    position:absolute;
    width:43px;
    height:40px;
    z-index:1;
    left: 0px;
    top: 0px;
}
-->
</style>
</head>
<body>
<div>
    <form id="form1" runat="server">
    <div>
    <div id="Layer1"><img src="green.gif" width="28" height="28" alt="a" />
  <div id="Layer2"><img src="red.gif" width="28" height="28" alt="a" id="a"/></div>
</div>
<p>&nbsp;</p>
  Insert  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
<p>&nbsp;</p>
<p><img alt="a" src="map.gif" width="672" height="587" usemap="#Map" />
  <map id="Map">
    <area  alt="a" shape="poly" onclick="hideTable()" 
coords="267,102,253,96,239,80,239,62,251,
48,241,34,229,24,236,21,243,17,252,10,267,9,
281,13,287,25,294,30,309,45,324,44,340,35,355,
42,351,56,345,74,332,85,349,101,333,107,312,
105,306,97,295,93,286,90,279,97,268,105,266,
104" href="#" />
              <area alt="a" shape="poly" id="Area1" style="border-color: #000000" 
coords="221,275,204,253,168,238,
155,210,166,194,202,187,226,168,238,
155,268,189,270,209,245,232,282,
220" href="#" />
  </map>
 
</p>

    </div>
</body>
</html>

Posted
Updated 10-Feb-10 18:36pm
v3

Hello!
This function has not closing bracket:
function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){

Here's the right way:
function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){<br />
 if (showItSwitch) {<br />
   elementToSet.style.display = "inline";<br />
   elementToSet.style.visibility = "visible";<br />
 } else {<br />
     elementToSet.style.display = "inline";<br />
     elementToSet.style.visibility = "hidden";<br />
  }<br />
}


Please pay attention to the last bracket.
To get the value of the cleck-box, you will have to inject its ID to javascript code: here's how:
setElementVisibility(document.getElementById("a"), false, document.getElementById('<%= TextBox1.ClientID %>').value);

Regards
 
Share this answer
 
v2
This will do good i think

C#
function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch)
{
     if (showItSwitch) 
     {
       elementToSet.style.display = "inline";
       elementToSet.style.visibility = "visible";
     }
 else
    {
       elementToSet.style.display = "inline";
       elementToSet.style.visibility = "hidden";
     }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900