bookmark - Javascript basics-changing form values Please read javascript basics-variables

Javascript basics-changing form values - Please read javascript basics-variables

 
 Discussion by Darren with 0 Replies.
 Last Update: September 9, 2004, 8:02 pm
 
bookmark - Javascript basics-changing form values Please read javascript basics-variables  
    
free web hosting
 
Before reading this: I would strongly suggest that you read Javascript basics-variables before going any further.

We will start off with changing form values! To begin, I have select the button input to be changed.

<script>
function changeme(){
document.frmbob.change.value="Changed"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Me" onclick="java script:changeme()">
</form>

-if then script-
<script>
function changeme(){
if(document.frmbob.change.value=="Changed"){alert("It Has Been Changed");}
else{document.frmbob.change.value="Changed";}
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Me" onclick="java script:changeme()">
</form>

The if statement is only going to be explained once. So pay attention. First, here a description of the statements used.
1. if(){} - This basically saying, if *something*, then do this {*}. The {} brackets are used the same way as a function.
2.A. == - Strictly (case sensitive). If you just use "=" it will change the variable.
2.A.1 Here is a demonstration of what goes wrong, if you use "=".
<script>
x=1;
if(x=20){alert("x is 20! But we just set x as 1...");}
if(x==1){alert("x is 1!");}
</script>
Can you guess how this would come out? If you guessed 20 your right! When Java hits "x=20", it makes x = 20.

2.B. != - Doesn't not equal this. if(password!="Bobo"){alert("Your Password is incorrect");}
2.C. > - Greater Then. if(x>1){alert("x is bigger then 1");}
2.D. >= - Greater Then or Equal To. if(x>=0){alert("x isn't a negative number");}
2.E. < - Less Then. if(x<1){alert("x is less then 1");}
2.F. <= - Less Then or Equal To. if(x<=1){alert("x isn't a possitive number");}

Cool, no? This is fairly simple, and if you are lost. Please read, "JavaScript for Beginners". Next We will change a text field.

<script>
function changeme(){
document.frmbob.change.value="Changed"
}
</script>
<form name="frmbob">
<input type="text" name="change" value="Change Me" onclick="java script:changeme()">
</form>

-if then script-
<script>
function changeme(){
if(document.frmbob.change.value=="Changed"){alert("It Has Been Changed");}
else{document.frmbob.change.value="Changed";}
}
</script>
<form name="frmbob">
<input type="text" name="change" value="Change Me" onclick="java script:changeme()">
</form>

I don't think it needs an explanation. This form of changing applies to nearly every form input. Next up, is changing the background color!


<script>
function changeme(){
document.bgColor="#c0c0c0"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>


-if then script-
<script>
function changeme(){
if(document.bgColor=="#c0c0c0"){alert("You Must Be Blind, the background has changed!");}
else{document.bgColor="#c0c0c0";}
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Again, this is pretty simple. Next on the list, changing the color of the font!

<script>
function changeme(){
document.body.text="#FF00FF"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Here is how to to change the link color.

<script>
function changeme(){
document.body.link="#FF00FF"
}
</script>
<a href="http://www.nowhere.com">No Where</a><br>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Thank you for reading another "JavaScript for Beginners" tutorial.
Bobo-

Body-
We will start off with changing form values! To begin, I have select the button input to changed.

<script>
function changeme(){
document.frmbob.change.value="Changed"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Me" onclick="java script:changeme()">
</form>

-if then script-
<script>
function changeme(){
if(document.frmbob.change.value=="Changed"){alert("It Has Been Changed");}
else{document.frmbob.change.value="Changed";}
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Me" onclick="java script:changeme()">
</form>

The if statement is only going to be explained once. So pay attention. First, here a description of the statements used.
1. if(){} - This basically saying, if *something*, then do this {*}. The {} brackets are used the same way as a function.
2.A. == - Strictly (case sensitive). If you just use "=" it will change the variable.
2.A.1 Here is a demonstration of what goes wrong, if you use "=".
<script>
x=1;
if(x=20){alert("x is 20! But we just set x as 1...");}
if(x==1){alert("x is 1!");}
</script>
Can you guess how this would come out? If you guessed 20 your right! When Java hits "x=20", it makes x = 20.

2.B. != - Doesn't not equal this. if(password!="Bobo"){alert("Your Password is incorrect");}
2.C. > - Greater Then. if(x>1){alert("x is bigger then 1");}
2.D. >= - Greater Then or Equal To. if(x>=0){alert("x isn't a negative number");}
2.E. < - Less Then. if(x<1){alert("x is less then 1");}
2.F. <= - Less Then or Equal To. if(x<=1){alert("x isn't a possitive number");}

Cool, no? This is fairly simple, and if you are lost. Please read, "JavaScript for Beginners". Next We will change a text field.

<script>
function changeme(){
document.frmbob.change.value="Changed"
}
</script>
<form name="frmbob">
<input type="text" name="change" value="Change Me" onclick="java script:changeme()">
</form>

-if then script-
<script>
function changeme(){
if(document.frmbob.change.value=="Changed"){alert("It Has Been Changed");}
else{document.frmbob.change.value="Changed";}
}
</script>
<form name="frmbob">
<input type="text" name="change" value="Change Me" onclick="java script:changeme()">
</form>

I don't think it needs an explanation. This form of changing applies to nearly every form input. Next up, is changing the background color!


<script>
function changeme(){
document.bgColor="#c0c0c0"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>


-if then script-
<script>
function changeme(){
if(document.bgColor=="#c0c0c0"){alert("You Must Be Blind, the background has changed!");}
else{document.bgColor="#c0c0c0";}
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Again, this is pretty simple. Next on the list, changing the color of the font!

<script>
function changeme(){
document.body.text="#FF00FF"
}
</script>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Here is how to to change the link color.

<script>
function changeme(){
document.body.link="#FF00FF"
}
</script>
<a href="http://www.nowhere.com">No Where</a><br>
<form name="frmbob">
<input type="button" name="change" value="Change Background" onclick="java script:changeme()">
</form>

Thankyou for reading my second Javascript basics tutorial.

Thu Sep 9, 2004    Reply    New Discussion   


Quickly Post to Javascript basics-changing form values Please read javascript basics-variables w/o signup Share Info about Javascript basics-changing form values Please read javascript basics-variables using Facebook, Twitter etc. email your friend about Javascript basics-changing form values Please read javascript basics-variables Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

javascript basic-variables   javascript basic-variables (4) (0) Macromedia Flash MX for beginners   Macromedia Flash MX for beginners