Skip to main content
added 6 characters in body
Source Link

I created a FiddleFiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText;responseText || ""; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word 'success' was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

PS. If you can you should only return the word true or false or success or failure instead of HTML and render the text plus image on the client.

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word 'success' was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

PS. If you can you should only return the word true or false or success or failure instead of HTML and render the text plus image on the client.

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText || ""; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word 'success' was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

PS. If you can you should only return the word true or false or success or failure instead of HTML and render the text plus image on the client.

Rewrote the answer with better example
Source Link

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word success'success' was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

PS. If you can you should only return the word true or false or success or failure instead of HTML and render the text plus image on the client.

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word success was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText; /* Change visibility based on outcome (success or not) */ if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; }​ 

Test with a regular expression if the word 'success' was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

PS. If you can you should only return the word true or false or success or failure instead of HTML and render the text plus image on the client.

Rewrote the answer with better example
Source Link

Add the following code to make the actual request..I created a Fiddle that probably does what you want.

The HTML

xmlhttp.open("GET","somepage.xml",true);<input id="submit" type="submit" /> xmlhttp.send(null);<span id="validate"></span>​ 

And are sure you want to assign in the if statement?The JavaScript

/* Success */ var WasresponseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" if(alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementByIDgetElementById("validate").innerHTML = "<imgresponseText; /* srcChange =\"success.gif\">success"visibility based on outcome (success or not) {*/  if(document.getElementByIDgetElementById("validate").innerHTML === "<img src =\"success.gif\">success"test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else {   document.getElementById("submit").style.visibility = 'hidden'; } 

Otherwise useTest with a regular expression if the triple === signword success was in the result or not. This way it doesn't really matter what the HTML in the response is.

And change theNote There is no getElementByID<success&gt; intoelement in HTML, use a getElementByIdspan or div.. with class success.

document.getElementById("validate").innerHTML 

Add the following code to make the actual request...

xmlhttp.open("GET","somepage.xml",true); xmlhttp.send(null); 

And are sure you want to assign in the if statement?

// Was... if(document.getElementByID("validate").innerHTML = "<img src =\"success.gif\">success") { if(document.getElementByID("validate").innerHTML === "<img src =\"success.gif\">success") { document.getElementById("submit").style.visibility = 'visible'; } else { document.getElementById("submit").style.visibility = 'hidden'; } 

Otherwise use the triple === sign.

And change the getElementByID into getElementById...

document.getElementById("validate").innerHTML 

I created a Fiddle that probably does what you want.

The HTML

<input id="submit" type="submit" /> <span id="validate"></span>​ 

The JavaScript

/* Success */ var responseText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used"; /* Failure */ //var responseText = "<img src=\"./images/Failed.gif\" alt=\"Incorrect!\">Can not be used"; /* Assign content */ document.getElementById("validate").innerHTML = responseText; /* Change visibility based on outcome (success or not) */  if(document.getElementById("validate").innerHTML.test(/success/gmi)) { document.getElementById("submit").style.visibility = 'visible'; } else {   document.getElementById("submit").style.visibility = 'hidden'; } 

Test with a regular expression if the word success was in the result or not. This way it doesn't really matter what the HTML in the response is.

Note There is no <success&gt; element in HTML, use a span or div with class success.

added 117 characters in body
Source Link
Loading
added 354 characters in body
Source Link
Loading
Source Link
Loading