Jump to content

new to form submission - getting error


ginerjm

Recommended Posts

As it says - my first attempt to submit a form via JS

 

Following an example I found :

 

document.forms["myform"].submit(); 

 

I tried the following in my validation function.  From the function arg I built a name for the form:

function ValidateEntry(i) {
frm = "entform"+i;
......}

 

My alert confirms that the form name is correct.

 

Then after going thru my code to do my validation, I attempted to submit the form with this:

 

document.forms[frm].submit();

 

The error message says:

"document.forms[...] is null or not an object"

 

I checked that I have no duplicate form names.  I checked that the form name appears in the browser code (IE - view,source).  I've also tried a variety of work-arounds, but none succeeded.  I even tried using getElementByID to do a submit but that "is not supported".

 

What am I missing here?

Link to comment
Share on other sites

I have posted the code.  I left out the alert immediately preceding the submit line, but I'm sure that the value of 'frm' is correct.  The line that fails is simply (exact code pasted below, not re-typed):

alert('form name being submitted is '+frm);
document.forms[frm].submit();

 

The whole js function is rather lengthy to be posting here.

Link to comment
Share on other sites

Well, you've seen the submit code.  Here's the form:

function DisplayAnEvent($e,$cntr)
{
global $php_path,$key,$hide;
echo "<tr>".PHP_EOL;
echo "<td><form id='entform$cntr' name='entform$cntr' method='POST' action='" . $php_path . 'tmsentry.php' . ">";
echo "<input type='$hide' class='ent_hide' name='eid' value='$key' size=1 tabindex=-1>";
echo "<input type='$hide' class='ent_hide' name='origevt' value='$e->event' size=1 tabindex=-1></td>";
$code=<<<heredocs
<td><input class="ent" type="text" id="evt$cntr" name="evt" value="$e->event" maxlength=5 size=5 onchange="PostChgMsg('Event')"></td>
<td><input type='$hide' class='ent_hide' id='pid$cntr' name='pid' value='$e->partner_id' size=1 tabindex=-1></td>
<td><input type='$hide' class='ent_hide' id = 'orig_pln$cntr' name='orig_pln' value='$e->part_ln' size=1 tabindex=-1></td>
<td><input class="ent" type="text" id = 'p_ln$cntr' name="p_ln" value="$e->part_ln" maxlength=25 size=29 onchange="PostChgMsg('Event')"></td>
<td><input type='$hide' class='ent_hide' id='orig_pfn$cntr' name='orig_pfn' value='$e->part_fn' size=1 tabindex=-1></td>
<td><input class="ent" type="text" id='p_fn$cntr' name="p_fn" value="$e->part_fn" maxlength=18 size=21 onchange="PostChgMsg('Event')">	</td>
<td><input type='$hide' class='ent_hide' id='orig_pmi$cntr' name='orig_pmi' value='$e->part_mi' size=1 tabindex=-1></td>
<td><input class="ent" type="text" id='p_mi$cntr' name="p_mi" value="$e->part_mi" maxlength=1 size=2 onchange="PostChgMsg('Event')">	</td>
<td><input class="ent" type="text" id="sttm$cntr" name="sttm" value="$e->starttime" maxlength=12 size=12 onchange="PostChgMsg('Event')">	</td>
<td><input class="ent" type="text" id="drpos$cntr" name="drpos" value="$e->drawpos" maxlength=2 size=3 onchange="PostChgMsg('Event')">	</td>
<td><input type='button' class='btn_sm' name='btn' onclick='return  ValidateEvent("$cntr","entform$cntr")' value='<- Update this Event'></td>
</tr></form>
heredocs;
echo $code;
}

 

Enjoy!

Link to comment
Share on other sites

Finally solved.  Once I added my missing closing form tag my JS submit now runs the script that the old 'submit' button used to do.  I now consider this problem solved.  See my next post for how to handle the value of the submit button which I no longer have available in my php script since JS did the submit.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.