Note: Both functions work for words of at least 1 letter. The second one will fail if given a word with no characters. The first one will produce "XXX".
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Last edited by Old Pedant; 11-13-2012 at 01:18 AM..
Note: Both functions work for words of at least 1 letter. The second one will fail if given a word with no characters. The first one will produce "XXX".
Ok thanks Guy
Now please, Can you tell me how to use a radio button and his function checked true, false? Because in www.w3schools.com I don't find how to use it!!!!
Ok thanks Guy
Now please, Can you tell me how to use a radio button and his function checked true, false? Because in www.w3schools.com I don't find how to use it!!!!
Not sure if w3schools would even cover how to do that since the javaScript covered there ismostly the antiquated version for Netscape 4 and earlier. The two guys who wrote the site in their spare time tried to cover so many different topics that they are struggling to keep any of them up to date and JavaScript has undergone enormous changes since they wrote their site and while they have added pages on the new commands they haven't updated the existing pages to reflect the changes in how they should be used.
To be able to make your code interactive you will first need to get rid of the document.write statement and replace it either with innerHTML calls or proper Document Object Model calls.
To attach processing to elements in the web page you need to be able to identify the element from the JavaScript (giving it an id and using getElementById is easiest but there are lots of other ways) and then attach an appropriate event handler or event listener to the element to specify what code to run when a specific event occursa on that element.
It's not easy, but here's how to find things on w3school:
Main page http://www.w3schools.com/ on right is "Web References" Find and click JavaScript. Bottom of page under "HTML DOM Objects Reference" is "Input Checkbox object" click. Your on the Checkbox Object page and under "Checkbox Object Properties" is "checked" On that page is an example on setting the box, getting the state of the box and a link to a "Try it yourself" page.
Not sure if w3schools would even cover how to do that since the javaScript covered there ismostly the antiquated version for Netscape 4 and earlier. The two guys who wrote the site in their spare time tried to cover so many different topics that they are struggling to keep any of them up to date and JavaScript has undergone enormous changes since they wrote their site and while they have added pages on the new commands they haven't updated the existing pages to reflect the changes in how they should be used.
To be able to make your code interactive you will first need to get rid of the document.write statement and replace it either with innerHTML calls or proper Document Object Model calls.
To attach processing to elements in the web page you need to be able to identify the element from the JavaScript (giving it an id and using getElementById is easiest but there are lots of other ways) and then attach an appropriate event handler or event listener to the element to specify what code to run when a specific event occursa on that element.
AN ok! Thanks for info! So my function checked have simple use: if female ad 40 at number of day date that i0m insert on text type, if male don't add anything and write only the number of day
Ummm...but you *ASKED* for
And that's not as simple.
A normal radio button, if there is only ONE of the given name=, can *NOT* be unchecked. Only checked.
You would need some mildly sneaky JavaScript code to be able to un-check a single radio button.
I don't think that's what you really wanted, based on your last post, but just be aware of it.
I badly explained, re ask my question
So my function day contains the document.getElementById (*day that i have selected from menù select*) and if select radio female button, add 40 at number that i selected from menù, else if I have selected male write only the number that I take from menù
I would like this method
Code:
<script>
function day (myDay)
{
Now write that I think :)
if (id = "male" == checked false)
{
var number;
number = myDay + 40;
}
else (id = "male" == checked true)
{
var number;
number = myDay;
}
alert (myDay);
}
</script>
<body>
<input type = "radio" name = "sex" id = "male" checked = "false" />
<input type = "radio" name = "sex" id = "female" checked = "true" />
Day: <select id = "myDay">
<option>1</option>
<option>2</option>
</select>
WOW! You know, you can *NOT* just make up your own language. You have to use the language AS IT EXISTS.
Code:
function day(myDay)
{
var num = myDay;
if ( document.getElementById("female").checked ) { num += 40; }
alert( num );
}
CAUTION: This *ASSUMES* that if "female" is *NOT* checked, then "male* *IS* checked.
If you want to be careful about it:
Code:
function day(myDay)
{
var num = "You did not check either radio button!";
if ( document.getElementById("male").checked ) { num = myDay; }
if ( document.getElementById("female").checked ) { num = myDay + 40; }
alert( num );
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
WOW! You know, you can *NOT* just make up your own language. You have to use the language AS IT EXISTS.
Code:
function day(myDay)
{
var num = myDay;
if ( document.getElementById("female").checked ) { num += 40; }
alert( num );
}
CAUTION: This *ASSUMES* that if "female" is *NOT* checked, then "male* *IS* checked.
If you want to be careful about it:
Code:
function day(myDay)
{
var num = "You did not check either radio button!";
if ( document.getElementById("male").checked ) { num = myDay; }
if ( document.getElementById("female").checked ) { num = myDay + 40; }
alert( num );
}
Ok, sorry but I don't know how take to input checked!!! And it's so Easy, only add getElementById ("").checked Thanks so much my mentor Master javascript!