Page 1 of 1
coding errors
Posted: Fri Nov 07, 2008 6:20 am
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;
}
}
Re: coding errors
Posted: Fri Nov 07, 2008 6:23 am
by VladSun
It's selectedIndex, not selectIndex!
Try
[js]document.form1.otherbox.innerHTML = otherBox;[/js]
Re: coding errors
Posted: Fri Nov 07, 2008 6:28 am
by flaming
Hi VladSun,
I've just put that in and it's now telling me that an object is required here
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
Re: coding errors
Posted: Fri Nov 07, 2008 6:31 am
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>
Re: coding errors
Posted: Fri Nov 07, 2008 6:34 am
by VladSun
flaming wrote:Hi VladSun,
I've just put that in and it's now telling me that an object is required here
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!
???
Re: coding errors
Posted: Fri Nov 07, 2008 6:45 am
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
Re: coding errors
Posted: Fri Nov 07, 2008 6:46 am
by VladSun
[js]onchange="otherFormCode(payment)"[/js]
is wrong ...
Re: coding errors
Posted: Fri Nov 07, 2008 7:02 am
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.
Re: coding errors
Posted: Fri Nov 07, 2008 7:32 am
by VladSun
The parameter passed to otherFormCode() should be a string - you are trying to pass a none existing object.
Re: coding errors
Posted: Fri Nov 07, 2008 7:43 am
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
Re: coding errors
Posted: Fri Nov 07, 2008 8:31 am
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

Re: coding errors
Posted: Fri Nov 07, 2008 10:11 am
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
Re: coding errors
Posted: Fri Nov 07, 2008 12:01 pm
by VladSun
It seems to be working (Opera 9) for me - what's wrong?
Re: coding errors
Posted: Fri Nov 07, 2008 12:29 pm
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>