Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 02, 2012 02:46 AM by tarunSaini
0 Points
8 Posts
May 01, 2012 08:27 PM|LINK
hello,
Im trying to write a program where it will change the value for 2 textboxs using ijavascript.
<html> <head> <title>"How are you"</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p> <input name="text1" type="text" id="text1" value="textbox 1" onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'"> </p> <p> <input name="text2" type="text" id="text2" value="textbox 2" onFocus="this.style.background = 'yellow'" onBlur="this.style.background='white'"> </p> <script type="text/javascript"> for(i = 0; i < 2; i++){ <p> <button onclick="document.getElementById('texti').value='how are you'">Click Me!</button> </p> </body> </html>
Star
8079 Points
1491 Posts
May 01, 2012 08:36 PM|LINK
use jQuery =)
<script type="text/javascript"> $(document).ready(function () { $('input[id^="text"]').val('Click Me!'); }); </script>
May 01, 2012 09:16 PM|LINK
is it possible to use a function ..something like this
<script type="text/javascript"> function popup() { alert("Hello World") for(i = 0; i < 2; i++){ <button onclick="document.getElementById('texti').value='how are you'">Click Me!</button> } </script> <input type="button" value="Click Me!" onclick="popup()"><br /> </body> </html>
May 01, 2012 09:43 PM|LINK
why would you do that?
for(i = 1; i < 2; i++){
var id = "text" + i;
<button onclick="document.getElementById(id).value='how are you'">Click Me!</button>
}
Contributor
2948 Points
985 Posts
May 02, 2012 02:46 AM|LINK
use this
<script>
function checking(form1)
{
for(i=0;i<5;i++)
//code your self here
form1.n1.value=form1.n2.value;
<body>
<form name="form1">
<input type="text" name-"n1" value="5">
<input type="text" name-"n2" value="10">
<input type="Button" value="ok" onClick="checking(form1);">
chris911
0 Points
8 Posts
buttons and forloop in javascript
May 01, 2012 08:27 PM|LINK
hello,
Im trying to write a program where it will change the value for 2 textboxs using ijavascript.
<html>
<head>
<title>"How are you"</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
<input name="text1" type="text" id="text1" value="textbox 1" onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'">
</p>
<p>
<input name="text2" type="text" id="text2" value="textbox 2" onFocus="this.style.background = 'yellow'" onBlur="this.style.background='white'">
</p>
<script type="text/javascript">
for(i = 0; i < 2; i++){
<p>
<button onclick="document.getElementById('texti').value='how are you'">Click Me!</button>
</p>
</body>
</html>
robwscott
Star
8079 Points
1491 Posts
Re: buttons and forloop in javascript
May 01, 2012 08:36 PM|LINK
use jQuery =)
<script type="text/javascript"> $(document).ready(function () { $('input[id^="text"]').val('Click Me!'); }); </script>Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
chris911
0 Points
8 Posts
Re: buttons and forloop in javascript
May 01, 2012 09:16 PM|LINK
is it possible to use a function ..something like this
<script type="text/javascript">
function popup() {
alert("Hello World")
for(i = 0; i < 2; i++){
<button onclick="document.getElementById('texti').value='how are you'">Click Me!</button>
}
</script>
<input type="button" value="Click Me!" onclick="popup()"><br />
</body>
</html>
robwscott
Star
8079 Points
1491 Posts
Re: buttons and forloop in javascript
May 01, 2012 09:43 PM|LINK
why would you do that?
for(i = 1; i < 2; i++){
var id = "text" + i;
<button onclick="document.getElementById(id).value='how are you'">Click Me!</button>
}
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
tarunSaini
Contributor
2948 Points
985 Posts
Re: buttons and forloop in javascript
May 02, 2012 02:46 AM|LINK
use this
<script>
function checking(form1)
{
for(i=0;i<5;i++)
{
//code your self here
form1.n1.value=form1.n2.value;
}
<body>
<form name="form1">
<input type="text" name-"n1" value="5">
<input type="text" name-"n2" value="10">
<input type="Button" value="ok" onClick="checking(form1);">