Results 1 to 5 of 5

Thread: Switch the 'action' field in an HTML form

  1. #1
    Join Date
    Aug 2006
    Posts
    139

    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

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    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.

  3. #3
    Join Date
    Nov 2008
    Posts
    996

    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>

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    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>

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    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>

Similar Threads

  1. Replies: 5
    Last Post: 25-05-2011, 10:21 PM
  2. How to make Opera remember form field entries
    By Ansari Bros in forum Technology & Internet
    Replies: 3
    Last Post: 02-01-2011, 07:29 PM
  3. Date field in HTML form
    By Messenger in forum Software Development
    Replies: 6
    Last Post: 29-07-2010, 10:30 AM
  4. Disable yellow autocomplete form field
    By teenQ in forum Technology & Internet
    Replies: 3
    Last Post: 06-08-2009, 09:57 PM
  5. To access a text field from another form
    By Sanket07 in forum Software Development
    Replies: 6
    Last Post: 06-02-2009, 06:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,864,195.02325 seconds with 17 queries