Solved

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

Posted on 2011-02-12
3
444 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp Google Map 2 27
Do alert on select 6 13
Where does legacy ASP.NET initialize language? 2 22
Wordpress Hacked 1 22
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

840 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