Welcome Guest, Not a member yet? Register   Sign In
Newbie BIG Javascript problem
#1

[eluser]homebru[/eluser]
I am brand new to CodeIgniter and I am (was) loving it!

I am converting an existing PHP application to CodeIgniter. I know my Javascript routines work just fine in PHP but running the exact same script in CodeIgniter always returns a debug error of "Undefined value". I have greatly simplified the Javascript function being called and written it 100 different ways but it ALWAYS returns the debug error "Undefined value".

What on EARTH am I doing wrong?

Here is what my javascript code has been pruned down to ('stats_top' is the name of my form):

function changeAcct ( )
{
document.stats_top.submit();
}

Sadly, my page depends on quite a few Javascript routines so without Javascript behaving properly, I'm up the creek...

Thanks in advance
#2

[eluser]Phil Sturgeon[/eluser]
Lets see the form code for this? I bet you have used form_open() and forgot to add the id in. Also, you might want to use getElementById() as it is better accross all browsers... I think?
#3

[eluser]homebru[/eluser]
I wish it were that simple. I am using a normal HTML <form> declaration. I've tried both getElementByID and getElementbyName. I have tried every variation I can think of and still nothing works.
#4

[eluser]homebru[/eluser]
Here's an excerpt of the code:


<form name="stats_top" id="stats_top" method="post" style="text-align:left;">
<label for="accnt"><strong>Account</strong></label>
<select name="accnt">
&lt;? foreach($clients->result() as $row): ?&gt;
<option value="&lt;?=$row->id ?&gt;" &lt;?=($id == $row->id) ? 'selected="selected"' : '' ?&gt;>&lt;?=$row->name ?&gt;</option>
&lt;? endforeach; ?&gt;
</select>

...

&lt;/form&gt;
#5

[eluser]homebru[/eluser]
Thanks for your help. I solved it.

I had some old code above the form that I had forgotten to remove and it was opening a form but not closing it which meant that I should have been using document.outer_form.top.submit();

But I didn't intend to nest forms (is that even possible?) so simply removing the old code fixed everything.

What a waste of time THAT was!!

I'm back to loving CodeIgniter now...
#6

[eluser]Nick Husher[/eluser]
As a minor nit to pick, be aware that the name property and the id property share the same namespace in the DOM tree.

With a few exceptions, it's invalid markup to have an element with the same name as an ID that already exists in the document (and vice-versa), even if they're the same element. The only exceptions to this are A, APPLET, FORM, FRAME, IFRAME, IMG, and MAP. Since you're doing it to a form, it's not a big deal, but it's something to be aware of.

Generally, it's good style to use only one or the other and not both.


[source]
#7

[eluser]homebru[/eluser]
I wasn't aware of that. Thanks. I normally do use one or the other but in this case, the CSS is using the ID and javascript would only respond to the NAME (without having to resort to the extra code lines to 'getElementByID()'.

I will remember your advise!




Theme © iAndrew 2016 - Forum software by © MyBB