coding errors

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

coding errors

Post by flaming »

can anyone tell me what is wrong with this javascript coding
i tried doing it in php and failed terribly.

so any help would be more than appreciated

Code: Select all

function otherFormCode(id){
        var elem = document.getElementById(id);
        var servi = elem.selectIndex;
        var otherBox = "<table>";
        
    if (servi == 5){
             otherBox = otherBox+"<tr><td>Other:</td><td><input type='text' name='otherbox' /></td></tr>";
             document.form1.otherbox.write otherBox;
            }
 
            else 
            {
            otherBox = otherBox+"<tr><td>Other:</td><td><input type='hidden' name='otherbox' value='N/A' /></td></tr>";
            document.form1.otherbox.write otherBox;
            return otherBox;
            }
            }
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

It's selectedIndex, not selectIndex!

Try
[js]document.form1.otherbox.innerHTML = otherBox;[/js]
There are 10 types of people in this world, those who understand binary and those who don't
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

Hi VladSun,

I've just put that in and it's now telling me that an object is required here

Code: Select all

var servi = elem.selectIndex;
which makes no sense to me because there is one in the elem var
also i noticed i missed out brakets around other box in the output
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

this might also help here is the part of the form i'm trying to use it on

Code: Select all

<table class="upper">
            <tr>
            <td>Trans Number</td> <td class="input"><input type="text" name="trans_id" id="trans-text" /></td>
            </tr>
            <tr>
            <td>Payment:</td><td class="input"><select name="payment" id="payment" onchange="otherFormCode(payment)">
            <option>--Please Select--</option>
            <option value="invoice">Invoice Payment</option>
            <option value="hardware">Hardware</option>
            <option value="software">Software</option>
            <option value="services">Services</option>
            <option value="other">Other</option>
            </select></td>
            </tr>
            </table>
            <div id="otherbox" >
            </div>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

flaming wrote:Hi VladSun,

I've just put that in and it's now telling me that an object is required here

Code: Select all

var servi = elem.selectIndex;
which makes no sense to me because there is one in the elem var
also i noticed i missed out brakets around other box in the output
VladSun wrote:It's selectedIndex, not selectIndex!
???
There are 10 types of people in this world, those who understand binary and those who don't
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

yeah sorry,i saw that after i'd posted
i've made all the changes and it's still giving me the object required error
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

[js]onchange="otherFormCode(payment)"[/js]
is wrong ...
There are 10 types of people in this world, those who understand binary and those who don't
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

i've taken the payment id out of the function on the form and it's still telling me that an object is required
thank you very much for this i'm new to the coding world and still plodding along slowly.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

The parameter passed to otherFormCode() should be a string - you are trying to pass a none existing object.
There are 10 types of people in this world, those who understand binary and those who don't
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

i've changed it to 'other' quoted like that and it's still telling me an object is required

the idea behind it is if someone clicks other a text box is shown in the div just below the table.
i've been told to look down the route i'm going by a lecturer and a mate from college
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

flaming wrote:i've changed it to 'other' quoted like that and it's still telling me an object is required
The function parameter, not the function call ;)
There are 10 types of people in this world, those who understand binary and those who don't
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: coding errors

Post by flaming »

i've done that as well still no joy

i can't see where i'm going wrong now
if i send a link to a page with it on could you have a look and see what you think from that??

http://eyeneye.co.uk/demo/

James
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: coding errors

Post by VladSun »

It seems to be working (Opera 9) for me - what's wrong?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: coding errors

Post by kaszu »

I assume you have problems with IE.
In the url you posted, there is an HTML:

Code: Select all

</tr>
<div id="otherbox">
</div>
</table>
which should be

Code: Select all

</tr></table>
<div id="otherbox">
</div>
Post Reply