Click to See Complete Forum and Search --> : Two javascript functions in one page


Squall Leonhart
11-20-2003, 11:45 AM
Hi, guys.
Can I have two functions in one page?
Please take a look at following code.

<script language="JavaScript" type="text/javascript">

function edit(frmEdit){
if(document.frmEdit.selectEdit.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}

function delete(frmDelete){
if(document.frmDelete.selectDel.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}
</script>


And browser tells me there is error on this line

function delete(frmDelete){
Expected '[' something like that.
Can you guys notice any problem? :confused: Thanks

runlevel007
11-20-2003, 11:57 AM
If frmEdit and frmDelete are objects then
remove "document." from your functions code.
Something like this:

<script language="JavaScript" type="text/javascript">

function edit(frmEdit){
if(frmEdit.selectEdit.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}

function delete(frmDelete){
if(frmDelete.selectDel.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}
</script>


If not then is should looks like:

<script language="JavaScript" type="text/javascript">

function edit(frmEdit){
if(document.all(frmEdit).selectEdit.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}

function delete(frmDelete){
if(document.all(frmDelete).selectDel.options.selectedIndex<0){
alert("Items are not selected");
return false;
}
return true;
}
</script>

Squall Leonhart
11-20-2003, 12:07 PM
Thanks for the reply.
But it still has same errors.....:(

runlevel007
11-20-2003, 12:16 PM
What are those "selectEdit" and "selectDel"? Dropdowns? on forms frmEdit, frmDelete?
If yes then you should remove "options". Try this:

selectEdit.selectedIndex

instead of

selectEdit.options.selectedIndex

jennAshton
11-20-2003, 04:14 PM
Looks like you're doing a validation of some sort with JS.
I'm not sure whether you have check boxes or drop down. If you're using drop down you should write your js like

document.your_form_name.your_input_name.selectedIndex == number_where_you_want_alert)

So, your code would be like following:

<script language="JavaScript" type="text/javascript">

function delete(frmDelete){
if(document.frmDelete.selectDel.selectedIndex==0){
alert("Items are not selected");
return false;
}
return true;
}
</script>