2

I have a page with this code:

<span class="cbCoreFieldsAjaxValue">
<label id="hidetodo1" style="color: #e05817;">
<strong>Click here</strong>
</label>
</span>

When user click (is an Ajax link), the code become this:

<span class="cbCoreFieldsAjaxValue" style="display: inline-block;">Yes</span>

I would like perform a page reload/refresh when the value is Yes. I suppose is necessary to use something like this:

if {
document.getElementById('hidetodo1').value="Yes";
location.reload();
}

but this of course don't work because my knowledge of javascript are too poor :-(

I don't have access to all html but I can make some modification if needed.

Somebody can help please ?

Thank

dotcom22
  • 249
  • 1
  • 7
  • 19

3 Answers3

1

I would suggest you should execute window.location.reload() inside the success handler of your XHR request. That would be the best thing to do.

But as your question says: You want to reload your page on changing content of span, Here are few points that you may like/find useful.

  1. You can detect change events on specific elements only using jquery. These elements are select, input and textarea. Read more here.
  2. You can not detect change events on other elements in my knowledge with simple javascript or jquery.
  3. Take a look at How to identify content change of an element

Once again, the best practice would be to do it (reload) in success handler.

Community
  • 1
  • 1
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
0

Inside <span class="cbCoreFieldsAjaxValue"> use:

<label id="hidetodo1" style="color: #e05817;">
<strong>Click here</strong>
</label>

before click and something like:

<label id="hidetodo1" style="color: #e05817;">Yes</label>

after click.

Then:

if (document.getElementById('hidetodo1').innerHTML == "Yes"){
    location.reload();
}

(if you're using the id="hidetodo1" for any other purpose in your scripts, make sure this new code doesn't cause any issues because id "hidetodo1" is now staying after it is clicked.)

Hope4You
  • 1,927
  • 4
  • 21
  • 45
0

Your if statement is incorrect. The if statement is missing condition

if /*WHERE IS THE CONDITIONAL STATEMENT??*/
{
document.getElementById('hidetodo1').value="Yes";
location.reload();
}

I think what you are looking for is:

if (document.getElementById('hidetodo1').value=="Yes") //When the value is "Yes"
{

   location.reload();//Reload the current page
}

UPD:

According to comments,the hidetodo1 element is a <label> - Label does not have a value property .

I guess you missed a text-box in your code. Add html code for text-box after label and use the id of a text box in getElementById argument.

Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71
  • 1
    The `hidetodo1` element is a ` – Ian May 10 '13 at 17:35
  • @Ian The question got updated. "Yes" is not contained in a `label` anymore. – Hope4You May 10 '13 at 17:35
  • 1
    @Hope4You Either way, neither have a `value` property. And the `` doesn't have that `id`. It has a specific `class` that could be targeted, but it's too unclear when they say "the code becomes this" – Ian May 10 '13 at 17:37
  • I updated my question. The problem is I don't have full html access. I can modify some thing. For example if is required to add a span with an Id instead to put a label I can do that.. – dotcom22 May 10 '13 at 17:47