Topic: onClick Event?

I am new to programming and do not know what I can and can not do with certain languages.

How can I create decisions on the fly? Would I use Javascript? For instance, if a radio button is selected and the value equals "sometext", then display a text field. Otherwise, do not display a text field.

Using pseudo-code, would this work or something similar to this?

<input type =radio onClick[$someVariable = true]; />

function sampleFunction()
{
if ($someVariable ==true)
{
document.write[<input type=text />];
}
}

Vote up Vote down

Re: onClick Event?

You do not create decisions on the fly. You pre-create the possible conditions that the user may choose.

What you want to do there is quite advanced and I think you should have few basic tutorials in Javascript first.

But to elaborate and expand on your idea, writing <input> or other HTML elements using Javascript is not really recommended. What you should do is have a script that can hide/show <div> or <p> block elements. Then place the inputs in the block elements and set their style to display:none. Then you can start using the events (onClick, onFocus, onBlur etc) to fire/initiate functions:

<p><input type="radio" id="radio1" onClick="myFunction();"></p>
<p id="hiddenElement1" style="display:none;"><input type="text" name="name" /></p>
<script type="text/javascript">
function myFunction(){
    var rd = document.getElementById('radio1');
    if(rd.checked){
        document.getElementById('hiddenElement1').style.display = 'block';
    };
};
</script>

Above is not tested, however it's just a basic idea of how you would write your code. However if you use "JQuery" javascript library, it will make your life 100% easier smile

Vote up Vote down

Re: onClick Event?

Nice tutorial and info about radio buttons here:

http://www.somacon.com/p143.php

Vote up Vote down