Forum Moderators: open

Message Too Old, No Replies

Form - CheckBox

assigning a value

         

fashezee

4:00 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do I assign a checkbox a value if it is not checked. My script is not working because the
variable must contain a value. i.e.

<input type="checkbox" name="temp" value="100">

How can I assign a value to a checkbox that has not been checked?

Nick_W

4:06 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Possibly I'm being thick and just not getting the point but I can't think why you would need to do that?

You caould just assign value="NULL" to unchecked boxes....

If I'm way off the mark can you give a little more detail?

Nick

jatar_k

4:07 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you shouldn't need to, if it isn't checked you shouldn't have to process the value at all. I am thinking that you may be going about it the wrong way.

What are you trying to do that makes you need a value there?

<added>at least we are of like mind Nick_W

fashezee

4:13 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using Coldfusion to process the form information. It gives me an error " VARIABLE NOT
DEFINED " when I submit the form without checking the boxes. When the boxes are checked,
everything works fine.

jatar_k

6:00 pm on Jul 12, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>You could just assign value="NULL" to unchecked boxes....

could you go with this fashezee?

when I saw cfm it was trouble because I have done some but not really very much.

It sounds like you are trying to process the value of the var without actually checking if it has a value first. Would it help if you tested the checkbox fields before you started trying to play with the data.

if they checked this field
process the information
else
continue

or something like that?

mavherick

6:10 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



You have to check if it's defined like jata_k said. In coldfusion you can do it like this:


<cfif IsDefined('form.temp')>
do something...
<cfelse>
do something else...
</cfif>

mavherick

moonbiter

6:23 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



I know nothing at all about Coldfusion, but I believe the problem is with checkboxes in HTML forms. I don't think that unchecked checkboxes are submitted at all with a form in HTML, so when you are trying to pull the variable from the submitted data there is nothing there.

I don't know that setting the value to null would do anything, since it isn't passing along the variable that null would be assigned to.

Of course, I could be wrong. ;)

Doesn't Coldfusion have any if statements? Like if(variable_exists) do something?

<edit>Oh, I see that it does. ;)</edit>

rewboss

6:52 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



null (sometimes spelt nul) means "no value", so assigning null to a variable essentially does nothing at all. I'm not sure it's even possible, in fact.

moonbiter

7:01 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



<script type="text/javascript">
var monkey = "ook ook!";
alert ("This variable has something in it\n" + monkey);
monkey = null;
alert ("This variable doesn't\n" + monkey);
</script>

moonbiter

11:08 pm on Jul 12, 2002 (gmt 0)

10+ Year Member



This probably is more instructive:

<script type="text/javascript">
// set monkey as a string object
var monkey = "ook ook!";
// set a string by way of example
var monkeyshine ="oop";
// set a generic object by way of example
var objMonkey = new Object(69);

alert("Right now, monkey is a "+typeof(monkey));
alert("And monkeyshine is a "+typeof(monkeyshine));
alert("While objMonkey is an "+typeof(objMonkey));
// now we set monkey to null
monkey = null;
alert("Having changed monkey to null, it is now an "+typeof(monkey));

try {
alert("Now we look at constructors. The constructor of monkeyshine is:"+monkeyshine.constructor);
alert("The constructor of objMonkey is:"+objMonkey.constructor);
// the following won't execute, because monkey is a null object with no properties
alert("The constructor of monkey is:"+monkey.constructor);
}
catch(e) {
alert("However, because it is set to null, monkey threw an exception error, namely: "+e.message);
}
finally {
alert("Whew! That's done");
}
</script>

wasmith

2:52 am on Jul 13, 2002 (gmt 0)

10+ Year Member



<input type="checkbox" name="temp" value="100">
<input type="checkbox" name="temp" myproperty="100">
<input type="checkbox" name="temp" I_like_blue="100">

if you are talking about IE then either temp.value or temp.myproperty or temp.I_like_blue all have are == to "100". but if you want the script to work with other browsers, stick to the normal properties of the tag IE
<input name="temp" type="hidden" value="100"> which are fully scriptable.

rewboss

7:22 am on Jul 13, 2002 (gmt 0)

10+ Year Member



var monkey = "ook ook!";

If this is a reference to the Librarian of Unseen University, you're in big trouble... ;)