Page 1 of 2

Form Submit button trigger programmatically?

Posted: Tue Nov 08, 2011 6:46 pm
by sblair
I'm trying to make my fields on the NB webpage live rather than having to hit a submit button each time. I found I can use the 'onChange' tag as shown below that will call a javascript function whenever the value for the field changes, which is perfect.

I now want to use that javascript function to programmatically hit the submit button. Below is the modified HtmlFormPost example with what I'm trying to do. I know html a bit better than javascript, so I'd prefer leaving all my actual forms in html rather than convert the entire thing to javascript. I just want to use javascript to post the form.

Thanks.
Scott

Code: Select all

<SCRIPT TYPE="text/javascript">
<!-- 
function submitchange(value)
{
     /* What goes here to submit the form using post? */	
	
    <!-- // alert("Test change"); -->
}
//-->
</SCRIPT>

<table>
<form action="form1" method=post>
  <tr>
    <td width=40> </td>
    <td>Enter data to post: <input type="text" name="textForm1" onChange="submitchange()" value="<!--FUNCTIONCALL WebTextForm1 -->"></td>
    <td><input type="submit" value="Submit"></td>
  </tr>
</form>
</table>

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 9:11 am
by Forrest
You are probably going to want to use ajax. There are a few examples of how to do this on the forum. Here's one: http://forum.embeddedethernet.com/viewt ... ?f=7&t=303

/edit.. Woops, read the first line on making your fields on the NB webpage live. That would be great for ajax. As for the submit button, not sure if ajax handles this.

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 9:27 am
by sblair
It's programmatically hitting the submit button to post back to the NB which is really the key.

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 1:42 pm
by BillC
Why dont you just google "Javascript submit", when I tried the first site that came up was http://www.javascript-coder.com/javascr ... bmit.phtml , it looks like this answers your question.

I hope this helps :) , Bill

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 1:48 pm
by sblair
That's one of the exact pages I was looking at last night Bill. Wasn't having luck getting it to work, I'm much more of a C guy here though so not sure yet why that didn't work...

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 1:51 pm
by BillC
I have used similar code on some of my projects, what does your code look like when using this function ?

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 1:58 pm
by sblair
I've tried a couple variations on the page you mentioned and then tried the following from a different page below. I have a multi-part form, so the field I'm testing with is part of "form5".

<SCRIPT TYPE="text/javascript">
<!--
function submitchange(value)
{

document.getElementById("form5").submit();

}
//-->
</SCRIPT>

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 2:04 pm
by BillC
going by the code in your first posting, you havent given your form a name to identify it, as sample below shows

<form name="myform" action="handle-data.php">


I would try this first, Bill

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 2:17 pm
by sblair
I had that in one of the versions I was testing last night... question is what should the "action" be? I assume somewhere I need to set it to be "post"?

In the html area for the form I have:

<form action="form5" method=post> which looks similar enough to confuse me.... ;)


Thanks.
Scott

Re: Form Submit button trigger programmatically?

Posted: Wed Nov 09, 2011 2:30 pm
by BillC
action should be set to the name of webpage that you want the data to be posted to.