Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-12
3
Medium Priority
?
461 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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

715 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