[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

creat a button

Posted on 2011-03-15
10
Medium Priority
?
210 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

656 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