Solved

creat a button

Posted on 2011-03-15
10
203 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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
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
Comment Utility
oops i forgot the function word

<script type="text/javascript">

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

</script>

sorry
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
@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:prafullamjn
Comment Utility
<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
Comment Utility
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
Comment Utility
>>
@CEHJ:

input tags should always be inside a form
>>

Yes, they should be <button>
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now