Click to See Complete Forum and Search --> : span value change


CobreX
01-17-2003, 03:33 PM
Dear Friends ,

I have problem about below script document.form1.errortext.value='OK'; line, I cant change
span' s value.

Please help
Thanks


<SCRIPT language=JavaScript>
<!-- Begin
function checkrequired() {

var fields = 0
var i = 0
var empty = true
var fields = document.form1.length
var textvalue = ""

for (i = 0; i < fields ; i++) {
switch (document.form1.elements[i].type){
case "select-one" :
break;
case "select-multiple" :
if (document.form1.elements[i].selectedIndex != -1){
empty = false
}
break;
case "checkbox" :
if ( document.form1.elements[i].checked) {
empty = false
}
break;
default :
break;
}
}

if (!empty) {
document.form1.submit();
} else {
document.form1.errortext.value='Select one or more item';
return false;

}
}
// End -->
</SCRIPT>

<form name=form1 method="POST" action="check.asp">

<SPAN class=errortext>You must check at least one of the available domain
names below to continue.</SPAN>

<input type="checkbox" name="k1" value="astim" class="input">
<input type="checkbox" name="k2" value="whax" class="input">
<input onclick="return checkrequired();" type="image" SRC="ok.gif" border="0" name="submitit" >
</form>

Webskater
01-17-2003, 03:40 PM
Your span tag must have a name. Your tag is:
<span class=errortext>
It should be:
<span name=errortext>
It can have a class as well if you like to format the contents.
However:
I think I am correct in saying that you can only refer to controls that accept the focus as:
document.formname.controlname
where formname is the name attribute of the control
e.g.
<forn name=ProductForm>
<input type=text name=ProductID>
</form>
This control would be referenced as:
document.ProductForm.ProductID
I am not convinced a span tag can be referenced the same way if it is inside <form></form> tags.
What will definitely work is to take the span tag outside the form tag and say:
<span id=errortext>
You will then be able to reference this as:
document.errortext

CobreX
01-17-2003, 03:55 PM
dear sir,

i tried to modify lines with your suggestion but i didnt accomplish it.

Can u modify and try lines for me?

Thanks

Webskater
01-17-2003, 04:33 PM
Sorry, must be getting late. A Span tag does not have a value attribute. You must say:
document.errortext.innerText='Select one or more item';

swon
01-17-2003, 04:34 PM
make the span as an elementobject with an id:

<SCRIPT language=JavaScript>
<!-- Begin
function checkrequired() {

var fields = 0
var i = 0
var empty = true
var fields = document.form1.length
var textvalue = ""

for (i = 0; i < fields ; i++) {
switch (document.form1.elements[i].type){
case "select-one" :
break;
case "select-multiple" :
if (document.form1.elements[i].selectedIndex != -1){
empty = false
}
break;
case "checkbox" :
if ( document.form1.elements[i].checked) {
empty = false
}
break;
default :
break;
}
}

if (!empty) {
document.form1.submit();
} else {
document.getElementById("errortext").innerHTML='Select one or more item';
return false;

}
}
// End -->
</SCRIPT>

<form name=form1 method="POST" action="check.asp">

<SPAN id=errortext>You must check at least one of the available domain
names below to continue.</SPAN><br>

<input type="checkbox" name="k1" value="astim" class="input">
<input type="checkbox" name="k2" value="whax" class="input">
<input onclick="return checkrequired();" type="image" SRC="ok.gif" border="0" name="submitit" >
</form>