Click to See Complete Forum and Search --> : calling functions through "onClick="
Jdvlpr
11-14-2003, 12:05 PM
Hi, This should be a rather simple problem, but it is getting me frustrated and feeling stupid. PLEASE HELP....
I have 2 functions (both defined within the same <Form></Form> tags):
1)
function GetModelPrice()
{
var Str = "?" + document.getElementById("Ma1").value + "~" + document.getElementById("Mdl").value;
var URLStr = "..\\..\\..\\..\\App\\GetOCPServlet" + Str;
window.open(URLStr, null, "height=300,width=500,status=yes,toolbar=no,menubar=yes,location=no");
}
2)
function GenIEst()
{
var sURL="..\\..\\..\\..\\aPP\GenIEstServlet";
document.getElementById("FORM1").action=sURL;
document.alert("message");
document.FORM1.submit();
}
And I have :
<H3 onClick="JavaScript:GetModelPrice()"><P><U>Click here to get Price for this Model</U></H3><BR>
<H3 Name="MsgButton2" onClick="JavaScript:GetIEst()"><P><B><U>GenIEst Here</U></B></H3>
in the same cell of a table.
Function 1) works fine every time but clicking on "GenIEst" resulted in an error message : "Error: Object doesn't support this property or method. Code=0" from IE5.
I have also tried calling GenIEst through "onClick=" from a submit button inside the same form and it didn't work. This form has Action="" inside the <Form> tag, and clicking on the submit button just brought me back to the same page again.
What am I doing wrong?
Thanks in advance.
K.
neil9999
11-14-2003, 12:20 PM
Get rid of the 'Javascript:' inside the onclick tags. You only need 'Javascript:' in front when you use some javasript as a url. eg. <a href="javascript:alert('hi')">
Neil
Jdvlpr
11-14-2003, 04:53 PM
Thanks Neil,
I tried taking out "JavaScript:" and it was the same. I got "Error: Object doesn't support this property or method. Code=0" from IE5 when I click on the <H3> part. And clicking on teh submit button did not update the "Action=" for the <Form > tag and, it brought me back to the same page again.
I also tried calling "GetModelPrice()" at the spots where I have onClick="GetIEst()" and they work... so I am really puzzled why GetModelPrice() works everywhere and not GetIEst().
HELP.
neil9999
11-15-2003, 01:58 AM
In your GetIEst() function, you have document.alert("message"). I think it's the document object that doesnt support the alert method. Just use alert("message). Could you provide the code for the form so i dont get all the errors when it cant find the form please?
Also, i've added a '\\'. I've highlighted it red. var sURL="..\\..\\..\\..\\aPP\\GenIEstServlet";
Heres the code i'm using to call the functions:
<button onclick="GetModelPrice()"><U>Click here to get Price for this Model</U></button>
<button name="MsgButton2" onclick="GetIEst()"><B><U>GenIEst Here</U></B></button>
There was also a new line inside the brackets of window.open(), which i took out and got rid of one of the three errors I was getting.
Neil
Jdvlpr
11-15-2003, 09:25 AM
Hi Neil,
Please find attached the Form code...
By the way, I have abbreviated some names in my original posting, I have made the same name changes in this form. Hope I haven't make any mistakes in this one.
Many Thanks.
K.
neil9999
11-16-2003, 02:02 PM
Hi
Quite a few times in your code you use things like document.getElementById("Make").value =infoStr[5];. I found that you had something with name="make" in, but nothing like id="Make". You must make sure that anything in your code you specify using document.getElementById("Make") has an id="" tag, but if you don't specify it that way, you use name="". And remember it's case sensitive.
Also, var infoStr is unspecified, and neither is infoStr[0], infoStr[1] etc. Search your code for silly mistakes likke these. And remember variable names are also case sensitive.
also in your code somewhere, you have //GetMAkeAndModelOCPrice();. If this is a function you want to run, remove the forward slashes and create the function, remembering case sensitivity.
Remember, var str="something" is only a variable in that function, str="something" can be called anywhere on the page
Hope this helps,
Neil
Jdvlpr
11-17-2003, 12:56 AM
Hi Neil,
Thanks again for your message. I appologize for having made it more confusing than it should have been. The last attached <Form> code was actually different to what the "real" piece of code was in that some of the function names were simplified or abbreviated. I should have just given you the "real" page to start with. Sorry again. Anyway, please find attached code for the actual page.
1) function "GetModelPrice()" is actually called "GetMakeAndModelOCPrice()" and this one works fine every time.
2) function "GenIEst()" is actually called "GenInternalEstimate()" and this is the one that does NOT work.
When this page is called with all the parameters in the query string at the end of the URL, the fields do get populated accordingly. infoStr, infoStr[0], infoStr[1] ..etc are defined and work fine. getElementByID("Make") also appeared to work properly.
The "GenInternalEstimate" submit button doesn't work (brings back to the same page, i.e. not updating the Action= as it should. So I tried using onClick= on an <H3> as an alternative, but that doesn't work either ("Error:Object doesn't support this property or method").
I appologize again and I hope you would still be kind enough to help me.
Thanks again.
K.
neil9999
11-17-2003, 10:18 AM
I think it's document.getElementById("LAYOUTFORM").action=sURL thats the problem, if i use the normal action="" tag in the LAYOUT form, it submits and goes of to another page. I don't think .action actually does anything. Does anyone else know how to change the action of a form, as I don't know how to do this, i'm afraid.
Neil
Jdvlpr
11-17-2003, 03:23 PM
Thanks anyway Neil, I have actually used getElementById("FormName").action in another project before and it worked fine. I think I have at long last have this resolved. When I take the function that modifies sURL outside of the form, it works, if it is defined inside the Form - it doesn't.
Sometimes I find it confusing whether certain codes should be placed inside / outside the Form, before / after the Body etc.
K.
neil9999
11-18-2003, 11:44 AM
Good, is everything working OK now?
Neil
Jdvlpr
11-18-2003, 02:33 PM
yes, it is working fine now. Thanks again.
K.