Form Submit button trigger programmatically?

Discussion to talk about software related topics only.
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Form Submit button trigger programmatically?

Post 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>
User avatar
Forrest
Posts: 289
Joined: Wed Apr 23, 2008 10:05 am

Re: Form Submit button trigger programmatically?

Post 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.
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Re: Form Submit button trigger programmatically?

Post by sblair »

It's programmatically hitting the submit button to post back to the NB which is really the key.
BillC
Posts: 72
Joined: Tue Oct 13, 2009 6:22 am
Location: Buckinghamshire, UK

Re: Form Submit button trigger programmatically?

Post 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
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Re: Form Submit button trigger programmatically?

Post 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...
BillC
Posts: 72
Joined: Tue Oct 13, 2009 6:22 am
Location: Buckinghamshire, UK

Re: Form Submit button trigger programmatically?

Post by BillC »

I have used similar code on some of my projects, what does your code look like when using this function ?
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Re: Form Submit button trigger programmatically?

Post 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>
BillC
Posts: 72
Joined: Tue Oct 13, 2009 6:22 am
Location: Buckinghamshire, UK

Re: Form Submit button trigger programmatically?

Post 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
sblair
Posts: 162
Joined: Mon Sep 12, 2011 1:54 pm

Re: Form Submit button trigger programmatically?

Post 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
BillC
Posts: 72
Joined: Tue Oct 13, 2009 6:22 am
Location: Buckinghamshire, UK

Re: Form Submit button trigger programmatically?

Post by BillC »

action should be set to the name of webpage that you want the data to be posted to.
Post Reply