Jump to content

Some insight and information please


phppup

Recommended Posts

I have two nearly identical radio button inputs that trigger JS alerts. 

The alert message will ONLY work when there are NO SPACES in the message. 

What am I doing wrong? 

What is the solution so that a message WITH spaces will be visible?

<!DOCTYPE html>
<html>
<body>

<p>Click the button get the text content of the button element.</p>

<button onclick="myFunction()" id="myBtn">Tryit</button>

<p id="demo"></p>

<script>

function myFunction() {
    var x = document.getElementById("myBtn").textContent;

document.write("<input type=radio onclick=alert('HelloWorld');> Click here and alert works")

  document.write("<br><br><br><br>")

document.write("<input type=radio onclick=alert('Hello World');> Click here and alert FAILS")
                                 //the ALERT will FAIL because of the SPACE between "Hello World"
 
 document.getElementById("demo").innerHTML = x; 
}
</script>

</body>
</html>

You can copy the code and wee for yourself.

Please advise.

 

Link to comment
Share on other sites

I added quotes to the TYPE attribute, but nothing changed.  Adding either single or double quotes to the ALERT render it totally inoperable.

document.write("<input type='radio' onclick=alert('Hello World');> Click here and alert FAILS")

Can you be more specific?

Link to comment
Share on other sites

Why do you think that adding quotes to the type attribute will have any impact on what the onclick does?

HTML attributes need quotes around the values. Your onclick does not have quotes. You need to figure out a way to put quotes there. Remember you have two types of quotes available to use.

Link to comment
Share on other sites

Not having much luck with double quotes inside the double quotes.  It seems as though the script is interpreting the second double quotes as the end of the statement rather than a continuation.

Am I missing some sort of syntax rule? Is there a requirement of double-single-double (or similar) in order to work along those lines?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.