Problem with code

Hi

I am having problems with the following code:
<!DOCTYPE>
<html>
<script type="text/javascript">
function ShowResult()
{
      x = document.forms["myform"]["newinput"].value;
      document.forms["myform"]["Result"].value = x;
}
</script>
<body>

<form action="/cgi-bin/html5.cgi" method="get" name="myform">
Enter a value : <input type="text" name="newinput"/>
<input type="button" value="Result" onclick="showResult();"/>
<output name="result"/>
</form>
</body>
</html>


For some reason the <output name="result"/> is coming up in red.  Could someone suggest a way of fixing it.
greg_cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shishir_sriCommented:
Hey. I found many errors in your code. The following code works fine for me:

<!DOCTYPE>
<html>
<head>
<script type="text/javascript">
function ShowResult()
{
      x = document.forms["myform"]["newinput"].value;
      document.forms["myform"]["result"].value = x;
}
</script>
</head>
<body>

<form action="/cgi-bin/html5.cgi" method="get" name="myform">
Enter a value : <input type="text" name="newinput"/>
<input type="button" value="Result" onclick="ShowResult();"/>
<output name="result"/>
</form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RartemassLife CoachCommented:
shishir_sri, I fail to see much of a difference in your code.
The only things I can discern is that you added a <head> tag (which is a good idea) and changed the 'r' in result on your line 8 to lowercase, and the 's' in ShowResult on your line 16 to uppercase.

Greg_c I would recommend wrapping the javascript in a head tag as shishir_sri has done and check again.
I'd guess that your HTML tag has some styling on it with a red font that the form is picking up. Moving the script into the head tag will alter the styling accordingly.
You can confirm this by changing the CSS (or where ever you are styling) so that the HTML uses green (or any colour really). If the form result changes to green you know the cause.
0
Dave BaldwinFixer of ProblemsCommented:
It looks like your format for the <output> tag is wrong.

http://www.w3schools.com/tags/tag_output.asp

In addition, javascript is case sensitive and 'Result' is not the same as 'result' with a small 'r'.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

shishir_sriCommented:
@Rartemass: Yes. Those are the only changes I made. This code is now working without any color issues. So, if the OP is facing those problems, its due to some external influence.
0
XGISCommented:
the code again....slight changes...prints the alphanumeric value in black.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function ShowResult() {
            x = document.forms["myform"]["newinput"].value;
            document.forms["myform"]["Result"].value = x;
        }
    </script>
</head>
<body>
    <form action="/cgi-bin/html5.cgi" method="get" name="myform">
        Enter a value :
        <input type="text" name="newinput" />
        <input type="button" value="Result" onclick="ShowResult();" />
        <output name="Result" />
    </form>
</body>
</html>

Open in new window

0
greg_cAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.