ginerjm Posted March 10, 2012 Share Posted March 10, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/ Share on other sites More sharing options...
AyKay47 Posted March 10, 2012 Share Posted March 10, 2012 have you checked to make sure that frm is what you expect it to be? Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325894 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 Yes - I said that first thing. I have plenty of alerts in my script checking everything. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325896 Share on other sites More sharing options...
AyKay47 Posted March 10, 2012 Share Posted March 10, 2012 if you are sure that frm is correct, then the variable is either getting overwritten or is not being injected correctly into the document.forms[] call. Post the entire relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325904 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325910 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 A thought - Does "document.forms" have to be built before referencing? Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325911 Share on other sites More sharing options...
AyKay47 Posted March 10, 2012 Share Posted March 10, 2012 i'm talking about most of the document. I want to see the <form> and the js used to submit it. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325916 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325918 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 Somewhat solved!! I left out a closing form tag for the form preceding my problem forms. Now I'm at least getting the submit to happen - although I still have some html errors occurring now. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325966 Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Author Share Posted March 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258650-new-to-form-submission-getting-error/#findComment-1325975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.