javascript submit problem : form won't submit

J

Joop

Hi all,

I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-)

So, here's my problem :

I've created a table in my document, presenting a list of items, one
can 'select' by clicking on it... (Kinda like a menu, you make your
choice from) But since this table can get very long, I've put
something of a 'search-form' on top, which enables the user to make a
selection of products from the list.

Now, the form uses a "post" method, and submits to itself, using the
form action. Some PHP script will make sure that the form is filled
out already, the next time it's presented.

The table, containing a list of products is presented, below the form.
When a user clicks on a product, the product should be "selected". At
first i just used a <a href="zoeken.php?prod_id=24"> link to do this,
but the problem is that my form won't remain in tact.

So now, the global idea is to submit the form after setting a hidden
form-field using JavaScript, using a onClick event.

Here's my code :

<-- the script -->

<head>
<script language="JavaScript">
<!--
var old_Color;

function select_this(id)
{
old_Color = document.getElementById(id).style.backgroundColor;
document.getElementById(id).style.backgroundColor = '#FFCCCC';
}

function deselect_this(id)
{
document.getElementById(id).style.backgroundColor = old_Color;
}

function submit_this(id)
{
document.forms['zoeken'].select_id.value = id;
document.forms['zoeken'].submit();
}
-->
</script>
</head>

<body>

<-- the form -->

<form name="zoeken" action="zoeken.php" method="post" style="margin:
5px;">

<-- a very long form with a lot of variable goes here -->

<input type="submit" value="Zoeken" class="formulierknop">
<input type="hidden" name="select_id" value="">

</form>


<-- the tablerows, in the table, all look like this -->

<tr id="1" onClick="submit_this(1);" onMouseOver="select_this(1);"
onMouseOut="deselect_this(1);" style="cursor: hand; background-color :
'transparent';">

</tr>


Cool huh?!? Everything seems to work, but the submit function. Did I
do something terribly wrong?!? I probably did... :-(

WHY WON'T MY FORM SUBMIT WHEN I CLICK ON A TABLE-ROW?!?!?!?!? :-S

Thnx in advance to everyone spending time on this! ;-)
 
H

hippo

Hi Joop,

I put your code in a html file (ie6.0) and it works...?

But what you can try to include your table (with the code rows)
between the <form></from> tags.

Maybe this works?

Hippo from [NL]
 
H

hippo

Sorry, but it also work in a php file.

No offense, but are you using table cells in your table rows?

Like:

<tr id="1" onClick="submit_this(1);" onMouseOver="select_this(1);"
onMouseOut="deselect_this(1);" style="cursor: hand; background-color :
'transparent';">

<td>blablabla</td>

</tr>

otherwise it is very difficult to determine where to click:)

Please response your results

Greetz,
Hippo from [NL]
 
J

Joop

Nope... Won't work either... Sorry... :-(

Anybody?!? I'm stuck at this for over a week now, and don't have the
foggiest idea to what's wrong...
 
H

hyperonyx

I have had this problem for several years an only just figured out how
to deal with it. There day I got this idea to check all of the
attributes of the from I was calling submit() on from a javascript
function. Low and behold.. Many of the attributes were blank. I've
had forms[].method, forms[].enctype, forms[].action all be empty and so
when you call forms[].submit(), nothing happens. I don't understand
why this happens either because those values are set in my <form> tag,
and somehow get lost. So my fix is to set them in the javascript
function if they are empyt.

For instance:

if( document.forms[index].action == "" )
document.forms[index].action = "multipart/form-data";
document.forms[index].submit();

It works so long as the action, method, and enctype are set.
It's also possible that some of the data you want in your <input> tags
isn't set as you expected. Check those as well if you have further
problems.

-Dieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top