We are writing a javascript where we are trying to pass an element name back to the server side. Here is what we are tring to do.
<SCRIPT LANGUAGE= "Javascript">
function DefForm(str) {
var ele=document.Form.elements;
var len=ele.length;
for (i=0;i<len;i++) {
if (ele[i].name = str)
{return ele[i].name}}}
</SCRIPT>
In the program we are doing
<cfif IsDefined("return DefForm('quoteStat#ctr#')") and other stuff. Will this retrun the element name back to the IsDefined function? We are using ColdFusion if this helps.
How do we get it to send back to the server? I have seen examples of other peoples problems and they are doing a return true or return false to the html code.
<SCRIPT LANGUAGE= "Javascript">
function DefForm(str) {
var ele=document.Form.elements;
var len=ele.length;
for (i=0;i<len;i++) {
if (ele[i].name = str)
{
window.location.href= self.location.href+"ele="+str;
}
}
}
</SCRIPT>
Swon,
Thanks for the help you given us so far. The item about the == was a typo on my part. I already had it that way in the program. What do I do about the portion of code in the program where it reads <cfif IsDefined("return DefForm('quoteStat#ctr#')")... should I take out the return portion and it will read then <cfif IsDefined("DefForm('quoteStat#ctr#')")?
I don't know exactly what you wanna do, but if you only need the value of the returned variable 'ele' you need only to get the variable with the get method, so I think there's no need for <cfif isDefined> one.
The Javascript code is quite often intertwined with HTML code.
The return code from a function will tell the HTML construct what to do.
For example, a form might have an onsubmit even handler. The JS event handler will return true or false and based on this value the form will/will not get submitted.
So, the return value can be used only on the client side.
An explanation od what we are tring to accomplish follows. We have radio buttons for selecting one of two choices. We have the ability to have these choices for one or more items, such as 1 yes no
2 yes no
3 yes no where yes and no are the radio buttons.
We have to know which row is yes and which one is no. Coldfusion will not allow us to concatenate a counter to the element such as form.quotestat#ctr# where ctr is the counter of rows. We came up with using Javascript to solve this problem. Each row would equate to quoteStat1, quoteStat2, quoteStat3. We need to know that the element exists which is where the IsDefined procedure comes in. <cfif> is an if statment. So we are tring to say if the form element exists and yes is selected do this or if no is selected do that.
There is a way in ColdFusion to test for a element with a counter at the end. We are using the Evaluate command to do this. Thanks for all your help in this matter.
Bookmarks