Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Switch the 'action' field in an HTML form

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-02-2010
MarceloQuad's Avatar
Member
 
Join Date: Aug 2006
Posts: 123
Switch the 'action' field in an HTML form

I have started the JavaScript one month ago. So, I don't have much knowledge about the JavaScript. Before I have done the C, C++ and HTML. But now I want to switch the action field which I am not able to do. I have tried many things, but not succeeded. Also I don't know how to Switch the 'action' field in an HTML form..?? I have tried to do it by simple way but its not working properly. I think that i would have to switch the action field in an HTML form dynamically. Please help me soon..!!
__________________
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little.
-Joe Martin
Reply With Quote
  #2  
Old 07-02-2010
Member
 
Join Date: Nov 2008
Posts: 1,193
Re: Switch the 'action' field in an HTML form

Since you have done HTML, I think that you will not find it tough. You may already have used the action field in an HTML form. The only thing is that you want to switch it now dynamically. In many scenarios, it is required that you need to send the data in the same form to different cgi scripts depending one certain criteria. JavaScript allows you to modify the action field of an HTML form dynamically. The following is the coding for the Radio Buttons which are used very frequently for input of the user. Also you will have to use the multiple submit buttons, according to the requirement.
Reply With Quote
  #3  
Old 07-02-2010
Member
 
Join Date: Nov 2008
Posts: 997
Re: Switch the 'action' field in an HTML form

The following is the script for the Radio Buttons. When you do it by yourself, then you will get an idea of using it. The below is the mentioned code :
Code:
<SCRIPT language="JavaScript">
function OnSubmitForm()
{
  if(document.myform.operation[0].checked == true)
  {
    document.myform.action ="insert.html";
  }
  else
  if(document.myform.operation[1].checked == true)
  {
    document.myform.action ="update.html";
  }
  return true;
}
</SCRIPT>
HTML Code:
<FORM name="form1" onSubmit="return OnSubmitForm();">
    Name: <INPUT TYPE="TEXT" Name="name"><br>
    Address: <INPUT TYPE="TEXT" Name="address"><br>
    <input type="radio" name="operation" value="1" checked>Insert
    <input type="radio" name="operation" value="2">Update
    <P>
    <INPUT TYPE="SUBMIT" name="Submit" VALUE="Save">
    </P>
 </FORM>
Reply With Quote
  #4  
Old 07-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: Switch the 'action' field in an HTML form

As said by the 'void' you can also use the multiple submit buttons on the form. You will get this by typing the following coding :
Code:
<SCRIPT language="JavaScript">
function OnSubmitForm()
{
  if(document.pressed == 'Insert')
  {
   document.myform.action ="insert.html";
  }
  else
  if(document.pressed == 'Update')
  {
    document.myform.action ="update.html";
  }
  return true;
}
</SCRIPT>
HTML Code:
<FORM name="myform" onSubmit="return OnSubmitForm();">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">

</FORM>
Reply With Quote
  #5  
Old 07-02-2010
Member
 
Join Date: May 2008
Posts: 1,990
Re: Switch the 'action' field in an HTML form

Several times you need to give the validations for certain fields on the form. Like user cannot keep the textbox of name empty while submitting his / her information. so you will have to do the proper validations. The following is the sample of the validation script :
Code:
<SCRIPT LANGUAGE="JavaScript">
var myformValidator = new Validator("myform");
myformValidator.addValidation("name","req","Please enter the proper name");
</SCRIPT>
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Switch the 'action' field in an HTML form"
Thread Thread Starter Forum Replies Last Post
Google Chrome is opening in basic HTML form instead of the Standard form Beatrix Technology & Internet 5 25-05-2011 11:21 PM
How to make Opera remember form field entries Ansari Bros Technology & Internet 3 02-01-2011 07:29 PM
Date field in HTML form Messenger Software Development 6 29-07-2010 11:30 AM
Disable yellow autocomplete form field teenQ Technology & Internet 3 06-08-2009 10:57 PM
To access a text field from another form Sanket07 Software Development 6 06-02-2009 06:42 PM


All times are GMT +5.5. The time now is 07:44 AM.