Solved

creat a button

Posted on 2011-03-15
10
205 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
Independent Software Vendors: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

733 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