JavaScript and client side scripting.
Moderator: General Moderators
flaming
Forum Newbie
Posts: 12 Joined: Tue Oct 21, 2008 9:57 am
Post
by flaming » Fri Nov 07, 2008 6:20 am
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;
}
}
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 6:23 am
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
Post
by flaming » Fri Nov 07, 2008 6:28 am
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
flaming
Forum Newbie
Posts: 12 Joined: Tue Oct 21, 2008 9:57 am
Post
by flaming » Fri Nov 07, 2008 6:31 am
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>
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 6:34 am
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!
???
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
Post
by flaming » Fri Nov 07, 2008 6:45 am
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
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 6:46 am
[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
Post
by flaming » Fri Nov 07, 2008 7:02 am
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.
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 7:32 am
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
Post
by flaming » Fri Nov 07, 2008 7:43 am
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
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 8:31 am
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
Post
by flaming » Fri Nov 07, 2008 10:11 am
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
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Fri Nov 07, 2008 12:01 pm
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
kaszu
Forum Regular
Posts: 749 Joined: Wed Jul 19, 2006 7:29 am
Post
by kaszu » Fri Nov 07, 2008 12:29 pm
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>