?
Solved

creat a button

Posted on 2011-03-15
10
Medium Priority
?
208 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

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.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Suggested Courses

771 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