Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluation of 'document.form_name.select.value' in Netscape 4? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi Guys,

I'd really appreciate some help from you. I have a page at that I'm having trouble with. It works fine with IE and with Netscape 6.2 onwards, but not with earier versions of Netscape.

The part to look at is at the bottom of the page where there is a drop down selector to choose the appropriate selection to add to the cart (Enhanced Simulation product).

Proper operation is when 'Add to Cart' button is clicked, without an appropriate selection made, then an alert comes up and prompts the user to select an option. If a selection is made in the drop down, and the 'Add to Cart' button is pressed, then the details relating to the selection are passed over to the cart by submitting the form.

The logic is accomplished by a function called simsubmit, located at the top of the HTML, see below:

note: the form is called 'sform', the drop down is called 'select'. The value 'none' is assigned to the default selection of the drop down, used to test for whether the product selection has been made.

function simsubmit()
{
if (document.sform.select.value=="none")
{
alert( "You need to select the simulation license first!");
}
else
{
document.sform.price.value=document.sform.select.value;

if (document.sform.select.value==375)
document.sform.product.value="{b}TARGET 3001! Light Simulation License{/b}";
else if (document.sform.select.value==995)
document.sform.product.value="{b}TARGET 3001! Pro Simulation License{/b}";

document.sform.submit();
}
}


The annoying thing is it works fine in IE and newest versions of Netscape.

OK so I'm willing to reward the person who first solves this one for me. A book or DVD/Video of your choice form Amazon if you get it sorted (up to order value of $50) and my thanks of course.

You can reach me directly at philip@puresoft.co.uk if you need further info.

Regards, Philip.
 
I think the problem is that you can't name the drop down list &quot;select&quot; try renaming it to select1. Select might already be used in javascript itself to mean a <select> box.

Rick if(($question==&quot;has been bugging me&quot;
AND $answer==&quot;fixed the problem&quot;) OR $answer==&quot;really good post&quot;){
print(&quot;Star&quot;);
}else{
print(&quot;Thanks.&quot;);
}
 
I tried re-naming the dropdown to sim_select, but this hasn't fixed it.

I'ts been annoying me for a long time. BTW, if anyone needs to get their hands on 4.x version of Netscape, there is an archive at
Thanks for the reply.

Still searching...

Regards, Philip.

philip@puresoft.co.uk
 
You don't have a select field named 'select'. I looked at your web page and it looks like the name of the field is 'sim_select'.

Your IF statement would then look like:

if(document.sform.sim_select.value==&quot;none&quot;) {.... There's always a better way...
 
I had already updated the code (including all references to select) to the newer version incase the name select had been the problem. I havn't changed it otherwise -so the problem is still as before.

The updated code is below - still the same result ufortunately.

function simsubmit()
{
if (document.sform.sim_select.value==&quot;none&quot;)
{
alert( &quot;You need to select the simulation license first!&quot;);
}
else
{
document.sform.price.value=document.sform.sim_select.value;

if (document.sform.sim_select.value==375)
document.sform.product.value=&quot;{b}TARGET 3001! Light Simulation License{/b}&quot;;
else if (document.sform.sim_select.value==995)
document.sform.product.value=&quot;{b}TARGET 3001! Pro Simulation License{/b}&quot;;

document.sform.submit();
}
}


Can anybody see an alternative way to code the same thing?

Thanks for the reply.

Still searching...

Regards, Philip.

philip@puresoft.co.uk

PS - Don't forget about the $50 reward for the solution!

 
Not sure if this will change anything...add to the <form>:
onSubmit=&quot;simsubmit()&quot;

Change this to
<input class=button type=submit name=&quot;Button&quot; value=&quot;Add to Cart&quot;>

Rick if(($question==&quot;has been bugging me&quot;
AND $answer==&quot;fixed the problem&quot;) OR $answer==&quot;really good post&quot;){
print(&quot;Star&quot;);
}else{
print(&quot;Thanks.&quot;);
}
 
Thanks for the idea, but I've just tried it and it didn't work. Changing the button to a submit didn't work because the point of the javascript is to stop a submit process unless the correct option is selected in the dropdown.

I tried adding the onSubmit=&quot;simsubmit()&quot; to the form tag but this only created a second iteration of the alert popup, otherwise no benefit.

Does anybody know any cascaded menu type system that could accomplish the same thing and be compatible?


Thanks for the reply.

Still searching...

Regards, Philip.

philip@puresoft.co.uk

PS - Don't forget about the $50 reward for the solution!

 
Phil,
The proper way of submitting forms with prior validation is this:

<form ... onSubmit=&quot;return(simsubmit())&quot;>
. . .
<input type=submit>
</form>

Also, remove this line:
[tt]document.sform.submit();[/tt]
from [tt]simsubmit()[/tt] function code.


This comes from this statement:
[tt]The submit button's onClick event handler cannot prevent a form from being submitted; instead, use the form's onSubmit event handler or use the submit method instead of a Submit object.
[/tt]
Taken from orignal Netscape JS 1.2 Guide.

I think this will solve your problem.
 
Thanks Starway, I tried your suggestions, but again to no avail. I did some further testing and the logic etc. is ok, as is the submit method - I just hard coded some test values of product desription and price in the existing simsubmit() function rather than doing the evaluation with the select drop down and it worked.

So it appears that the problem is only with the evaluation statement using the drop down list. Still I can't find a way of even using other intermediate/container variables since you can't seem to have separate events associated with each element in the drop down list, rather just with the drop down as a whole.

I'm thinking now there is no way around this for the drop down!

Maybe I'll just have to use individual radio buttons or check boxes.

The only other alternative I can think of that would be as good is a CSS drop down menu to acheive the same results. I know it seems rather over the top for a single product there, but I've actually got another order page with several of these type of options required for each product, so it would be useful. Anybody point me to some good example code/sites for this.

Regards, Philip.
 
Try changing this everywhere it appears in your code:
document.sform.price.value
to this:
document.sform.price.options[selectedIndex].value

Rick if(($question==&quot;has been bugging me&quot;
AND $answer==&quot;fixed the problem&quot;) OR $answer==&quot;really good post&quot;){
print(&quot;Star&quot;);
}else{
print(&quot;Thanks.&quot;);
}
 
I hope this works. I think it will:


function simsubmit(that)
{
if (that.options[that.selectedIndex].value==&quot;none&quot;)
{
alert( &quot;You need to select the simulation license first!&quot;);
}
else
{
document.sform.price.value=that.options[that.selectedIndex].value;

if (
that.options[that.selectedIndex].value==375)
document.sform.product.value=&quot;{b}TARGET 3001! Light Simulation License{/b}&quot;;
else if (that.options[that.selectedIndex].value==995)
document.sform.product.value=&quot;{b}TARGET 3001! Pro Simulation License{/b}&quot;;

document.sform.submit();
}
}


The easiest way is to call it like this from the select:

<select onChange=&quot;simsubmit(this);&quot;>

If you don't want that, this should work:

<input type=button onClick=&quot;simsubmit(document.sform.sim_select);&quot;>

Rick if(($question==&quot;has been bugging me&quot;
AND $answer==&quot;fixed the problem&quot;) OR $answer==&quot;really good post&quot;){
print(&quot;Star&quot;);
}else{
print(&quot;Thanks.&quot;);
}
 
Yes! That works wonderfully. Thank you so much. I had almost given up on it!

Rick, send me an e-mail so I can send something to you...

Regards, Philip Hodgers.

philip@puresoft.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top