Solved

On post back the value entered to an element using javascript is gone

Posted on 2011-02-12
3
452 Views
Last Modified: 2012-05-11
I have asp:button, whoch on click calls a javascript function to assign the date to a html (p) element. I can see the datetime for a second, but I think on postback the value of the element is gone. How do I make sure after the user clicks on the button the datetime value is still shown. I have attached the code thnaks
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
    <script type="text/javascript">
        function displayDate() {
            document.getElementById("demo").innerHTML = Date();
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    
    
<h1>My First Web Page</h1>

<p id="demo"></p>
<asp:Button ID="btn" Text="disp" runat="server" OnClientClick="return displayDate();" />
</form>
</body>
</html>

Open in new window

0
Comment
Question by:TrialUser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34879762
Hi,

Add return false in your javascript function.

I have modified your code below :
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
    <script type="text/javascript">
      function displayDate() {
        document.getElementById("demo").innerHTML = Date();
        return false;
      }
</script>
</head>
<body>
    <form id="form1" runat="server">
    
    
<h1>My First Web Page</h1>

<p id="demo"></p>
<asp:Button ID="btn" Text="disp" runat="server" OnClientClick="return displayDate();" />
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:TrialUser
ID: 34879922
oh perfect thx
0
 

Author Closing Comment

by:TrialUser
ID: 34879928
thx
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question