Forum Moderators: open

Message Too Old, No Replies

href form submit problem

Works in IE but not in FireFox

         

DaSingh

4:11 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



I've got the following PHP script which basically creates links of the alphabet for searching a database

echo "<form name=\"char\" action=\"clients.php\" method=\"post\">";
echo "<input name=\"val\" type=\"hidden\" value=\"\">";
$c = "a";
for ($i=0;$i<26;$i++) {
echo "<a href=\"javascript:submitform();\" onMouseOver=\"change('".$c."')\">".strtoupper($c)."</a>\n\t";
$c++;
}
echo "</form>";

I have this JavaScript for the links

<script language="JavaScript" type="text/javascript">
function submitform() {document.char.submit() }
function change($ch) {document.char.val.value=$ch;}
</script>

The change function changes the value in the hidden field to the link selected. This all works fine in IE but for some reason it wont submit in FireFox

Any ideas on what I'm doing wrong?

Thanks

kaled

6:50 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know nothing of php, but I don't think javascript interpreters will like the use of $ to precede variable names.

Since this is the javascript forum, when posting code snippets, it would be more helpful if you posted html source code rather than php.

In general, when trying to figure out why javascript code won't work, it is always helpful to open a javascript console (to display error messages). I reckon Opera is best for this, closely followed by Firefox.

Kaled.

DaSingh

8:18 am on Jul 26, 2005 (gmt 0)

10+ Year Member



Sorry the HTML which is created from the PHP is as follows:

<form name="char" action="clients.php" method="post">
<input name="val" type="hidden" value="">
<a href="javascript:submitform();" onMouseOver="change('a')" class="links">A</a>
<a href="javascript:submitform();" onMouseOver="change('b')" class="links">B</a>
<a href="javascript:submitform();" onMouseOver="change('c')" class="links">C</a>
<a href="javascript:submitform();" onMouseOver="change('d')" class="links">D</a>
(ALL THE WAY TO Z)
</form>

Then the same JavaScript above is used for the functions:

I have this JavaScript for the links

<script language="JavaScript" type="text/javascript">
function submitform() {document.char.submit() }
function change($ch) {document.char.val.value=$ch;}
</script>

Cant for some reason get it to work in Firefox

Thanks

DaSingh

8:57 am on Jul 26, 2005 (gmt 0)

10+ Year Member



I get these errors in the JavaScript console in FireFox

Error: missing name after . operator
Source File: [***********...]
Line: 8, Column: 32
Source Code:
function submitform() {document.char.submit() }

Plus this:

Error: submitform is not defined
Source File: javascript:submitform();
Line: 1

And this:

Error: change is not defined

I'm confused?!?!?!?

dcrombie

11:12 am on Jul 26, 2005 (gmt 0)



Your first problem is the '$' in the JavaScript function - unless that was a typo. The other problem is that "char" may be a reserved word in some browsers.

The following code worked for me:

function submitform()  
{
document.forms["char"].submit();
}

function change(ch)  
{
document.forms["char"].val.value = ch;
}