Solved

creat a button

Posted on 2011-03-15
10
206 Views
Last Modified: 2012-05-11
hello,


i have a html code and a bit of java the code is running automatically
i want to create a button and when the button is pusht the  code shuld run ,

i dont know how to do it i used <button> but dident work for me

here is my code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>11</title>
	</head>
	<body>
		
		<img src="MyNameIs.jpg"/>
		<br />
		

		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "uw naam is " + name );
		
		number = parseInt (prompt("give a number"));
		document.write("<br /> letter " + number + " is een "  + name.charAt(number-1) ); 
            document.write("<br /> de lengte van je naam is " + name.length + " posities");
		document.write("<br /> vanaf positie " + number + " tot einde, blijft nog: "  + name.substring(number));
	


	</script>
	</body>
	

</html>

Open in new window

0
Comment
Question by:kensy11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35143165
your question is in the wrong zone. Please ask for it to be moved into the Javascript zone.
0
 
LVL 4

Expert Comment

by:dwkd
ID: 35143192
try
<script type="text/javascript">

SayMyName(myname){
alert("I believe your name is "+myname);
}

</script>

<input type="button" name="ClickMe" value=" Click Me " onclick="SayMyName('Mike');"/>


0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35143195
This is a little odd, but I think this is what you want it to do:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>11</title>
</head>
<body>

<img src="MyNameIs.jpg"/>
<br />


<script type="text/javascript">

function DoPrompt()
{
	name = prompt("your last name");
	name = name.toUpperCase();
	document.write( "uw naam is " + name );

	number = parseInt (prompt("give a number"));
	document.write("<br /> letter " + number + " is een "  + name.charAt(number-1) ); 
	document.write("<br /> de lengte van je naam is " + name.length + " posities");
	document.write("<br /> vanaf positie " + number + " tot einde, blijft nog: "  + name.substring(number));
}

</script>

<form>
<input type=button onclick="DoPrompt()" value="Click Here">
</form>
</body>


</html>

Open in new window

0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 35143202
Try something like the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>11</title>
    </head>
    <body>

	<img src="MyNameIs.jpg"/>
	<br />


	<script type="text/javascript">
	    function personal() {
		name = prompt("your last name");
		name = name.toUpperCase();
		var output = "uw naam is " + name 

		number = parseInt (prompt("give a number"));
		output = "<br /> letter " + number + " is een "  + name.charAt(number-1); 
		output += "<br /> de lengte van je naam is " + name.length + " posities";
		output += "<br /> vanaf positie " + number + " tot einde, blijft nog: "  + name.substring(number);
		document.getElementById("result").innerHTML = output;
	    }



</script>

<div><input type="button" value="Run" onclick="personal()"></input><span id="result"></span></div>
	</body>


    </html>

Open in new window

0
 
LVL 4

Expert Comment

by:dwkd
ID: 35143209
oops i forgot the function word

<script type="text/javascript">

function SayMyName(myname){
alert("I believe your name is "+myname);
}

</script>

sorry
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35143317
@CEHJ:

input tags should always be inside a form

Naked input tags do not work across browsers:

http://www.codingforums.com/showthread.php?t=159827
0
 
LVL 3

Expert Comment

by:Prafulla Maharjan
ID: 35144624
<a class="button" href="#" "></a>

create a button class in the css

and just u call

it will help u

0
 
LVL 4

Expert Comment

by:dwkd
ID: 35149172
or just have a button that doesn't need to be inside a form:

            <script type="text/javascript">

          function SayName() {
                name = prompt("your last name");
            name = name.toUpperCase();
            document.write( "uw naam is " + name );
            
            number = parseInt (prompt("give a number"));
            document.write("<br /> letter " + number + " is een "  + name.charAt(number-1) );
                document.write("<br /> de lengte van je naam is " + name.length + " posities");
            document.write("<br /> vanaf positie " + number + " tot einde, blijft nog: "  + name.substring(number));
            }
            </script>


            and in your body:

            <button type="button" onclick="SayName();"> go </button>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35149830
>>
@CEHJ:

input tags should always be inside a form
>>

Yes, they should be <button>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35376290
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
This article discusses how to implement server side field validation and display customized error messages to the client.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question