I have a link at a page. It has a email form that sends an email to my address. I want to thank sender. I'm redirecting to another page that thanks the user. But i want a thank notification to be displayed in the same page with close option. Please help of with code.

Too vague requirement... The easiest way is to use a popup. Try to do it with alert() function first to see if the function is called correctly.

Well, I could do that but i wanna have little fancy.

I got an idea. What i can do is have a form or div with thank notification. I can hide and remove it from flow at normal page load an show when an email has been sent. For this we need two functions: one each to show and hide. But i have a problem about calling show function after an email has been sent. When the page loads normally i call a hide function on page load.

Dillip:

OK, may be like this...

<html>
<head>
<style type="text/css">
.body_part {
  position: relative; /* force the hidden div to display inside */
  width: 100%;
  height: 600px;
  border: 2px solid gray;
}
.hidden_main_style {
  position: absolute;
}
.hidden_sub_style1 {
  top: 0px;
  left: 0px;
  display: none;
  visibility: hidden;
  z-index: 0;
}
.hidden_sub_style2 {
  top: 100px;
  left: 100px;
  z-index: 10;
}
</style>

<script type="text/javascript">
function showHiddenMessage(hiddenDivId) {
  var hiddenElement = document.getElementById(hiddenDivId)
  if (hiddenElement) {  // the element exists
    hiddenElement.className = hiddenElement.className.replace(/style1/, "style2")
    window.setTimeout("keepShowing('"+hiddenDivId+"', 4)", 1000) // count down 1 sec before calling keepShowing
  }
}

function keepShowing(hiddenDivId, time) {
  time = parseInt(time,10) // ensure integer
  if (time>0) {  // keep showing
    window.setTimeout("keepShowing('"+hiddenDivId+"', "+(time-1)+")", 1000)
  }
  else {
    var hiddenElement = document.getElementById(hiddenDivId)
    if (hiddenElement) {  // the element exists
      hiddenElement.className = hiddenElement.className.replace(/style2/, "style1")
    }
  }
}
</script>
</head>

<body>
<div class="body_part">
<input type="button" value="Submit" onclick="showHiddenMessage('my_hidden_div')">
<div id="my_hidden_div" class="hidden_main_style hidden_sub_style1">
Thank you!!!
</div>
</div>
</body>
</html>

Thats not what i actually want. I want to load same page and load another function on onload instead of mentioned on onload in the page.

"load same page and load another function on onload instead of mentioned on onload in the page"
Not sure what you mean here... You want the function to be in the window.onload but the script should be executed after other functions in the onload? Or you want to put the function in the page init? In other words, you want to hide the script from view source? Not sure you can hide your script source from client side anyway...

Okay that seems not to be possible. I'v thought of another way. Using cookies. First i set a cookie when an email has been sent. And checking the existence of cookie i decide to call which function. I had viewed the way of setting cookie in w3schools but i found it two messy to understand. Please give an easy example of setting cookie and checking its existence.

I am unable to got it.Can you please explain.

I just need an easy example to set a cookie and another to check if it exists.

If you want to do cookies in JS, check this one out. It will teach you how to implement and deal with your own cookies.

okay thanks... I shall see further...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.