Jump to content

[SOLVED] Javascript and forms action help


AbydosGater

Recommended Posts

Hi guys,

Here, i am really stuck as dont know anything about javascript.

 

I am writing a form.. and one of the fields in the form is going to be for "Your Domain".

 

What i need help on, is figuring out.. when a user puts say.. domain.com in the box.. That the forms "action=" method is changed to the domain ie: <form action="domain.com/process_form">..

 

Javascript is the only way i can thing about doing this.. But i dont know Javascript.

 

Could someone please help me!

Andy

Link to comment
Share on other sites

you could make a simple javascript function like so:

 

function submitForm(formid, actionURL)
{
  form_handle = document.getElementById(formid);
  form_handle.action = actionURL;
  form_handle.submit();
  return true;
}

 

and in the form's submit button, use:

 

<input type="submit" name="Your Domain" onclick="javascript:submitForm(thisformsid, 'domain.com/process_form');" />

 

the reason we still use a submit input type is so that those with javascript can still submit the form - it'll just head to the form's default action.

Link to comment
Share on other sites

let's assume the ID of our input textbox is called "targetDomain" and that our form's ID is "formOfMysteryAndWonder":

 

function customSubmit()
{
  form_handle = document.getElementById("formOfMysterAndWonder");
  custom_action = document.getElementById("targetDomain").value;

  if (custom_action != '')
  {
    form_handle.action = custom_action;
    form_handle.submit();
    return true;
  }
  else
  {
    return false;
  }
}

 

submit button:

 

<input type="submit" name="do_this_thang" value="Go To Your Domain" onclick="return customSubmit();" />

 

give this a shot.  i have a habit of needing to troubleshoot my javascript functions, so it may not work out of the box, to warn you.

Link to comment
Share on other sites

alright, well we might as well just drop the submit accessibility to do some bug checking:

 

function customSubmit()
{
  form_handle = document.getElementById("formOfMysterAndWonder");
  custom_action = document.getElementById("targetDomain").value;

  if (custom_action != '')
  {
    form_handle.action = custom_action;
    form_handle.submit();
  }
}

 

<input type="button" name="do_this_thang" value="Go To Your Domain" onclick="customSubmit();" />

 

keep in mind the javascript console in FF is extremely handy for javascripting.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.